Skip to content

Conversation

@samsja
Copy link
Member

@samsja samsja commented Dec 2, 2022

Context

introducing the stacked mode for faster computation and saving memory when dealing with tensor when needed:

class Image(Document):
    tensor: TorchTensor[3, 224, 224]

batch = DocumentArray[Image](
    [Image(tensor=torch.zeros(3, 224, 224)) for _ in range(10)]
)

batch.stack()
assert (batch.tensor == torch.zeros(10, 3, 224, 224)).all()
assert batch.is_stack()
batch.unstack()

We expose as well a context manager

with batch.stacked_mode():
    ...

with batch.unstacked_mode():
   ...

@samsja samsja marked this pull request as draft December 2, 2022 10:26
@samsja samsja changed the title Feat tensor column mode feat(v2): tensor column mode Dec 2, 2022
@github-actions github-actions bot added size/l and removed size/m labels Dec 5, 2022
@samsja samsja force-pushed the feat-tensor-column-mode branch from fe10440 to 31d85d8 Compare December 5, 2022 15:27
@samsja samsja requested a review from alexcg1 December 5, 2022 16:40
@samsja samsja marked this pull request as ready for review December 5, 2022 16:41
@samsja samsja force-pushed the feat-tensor-column-mode branch from 915406d to 342a726 Compare December 5, 2022 16:41
@samsja samsja force-pushed the feat-tensor-column-mode branch 3 times, most recently from 63c74c7 to 62671f3 Compare December 6, 2022 10:01
**Unstacked mode (default)**:
In this case a DocumentArray is a list of Documents and each Document owns its data.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does it mean to for a Document to "own" data?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it means that the data is bound to the lifecycle of the Document. If the Document go out of scope the data as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it also be accurate to say the Document stores the data?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here owning the the good term from a computer science point of view

@samsja samsja force-pushed the feat-tensor-column-mode branch from 78b7968 to b6770d2 Compare December 6, 2022 12:58
samsja and others added 15 commits December 6, 2022 14:01
Signed-off-by: Sami Jaghouar <[email protected]>
Co-authored-by: Johannes Messner <[email protected]>
Signed-off-by: samsja <[email protected]>
Signed-off-by: Sami Jaghouar <[email protected]>
Signed-off-by: Sami Jaghouar <[email protected]>
Signed-off-by: Sami Jaghouar <[email protected]>
Signed-off-by: Sami Jaghouar <[email protected]>
Signed-off-by: Sami Jaghouar <[email protected]>
Co-authored-by: Alex Cureton-Griffiths <[email protected]>
Signed-off-by: samsja <[email protected]>
Signed-off-by: Sami Jaghouar <[email protected]>
Co-authored-by: Alex Cureton-Griffiths <[email protected]>
Signed-off-by: samsja <[email protected]>
Signed-off-by: Sami Jaghouar <[email protected]>
Signed-off-by: Sami Jaghouar <[email protected]>
Signed-off-by: Sami Jaghouar <[email protected]>
@samsja samsja force-pushed the feat-tensor-column-mode branch from b6770d2 to 0b3f538 Compare December 6, 2022 13:01
Signed-off-by: Sami Jaghouar <[email protected]>
Signed-off-by: Sami Jaghouar <[email protected]>
Copy link
Contributor

@alexcg1 alexcg1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed a few things last time round 😅

**Unstacked mode (default)**:
In this case a DocumentArray is a list of Documents and each Document owns its data.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it also be accurate to say the Document stores the data?

samsja and others added 4 commits December 6, 2022 15:37
Signed-off-by: Sami Jaghouar <[email protected]>
Co-authored-by: Alex Cureton-Griffiths <[email protected]>
Signed-off-by: samsja <[email protected]>
Co-authored-by: Alex Cureton-Griffiths <[email protected]>
Signed-off-by: samsja <[email protected]>
Signed-off-by: Sami Jaghouar <[email protected]>
Copy link
Contributor

@alexcg1 alexcg1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Signed-off-by: Sami Jaghouar <[email protected]>
@github-actions
Copy link

github-actions bot commented Dec 6, 2022

📝 Docs are deployed on https://ft-feat-tensor-column-mode--jina-docs.netlify.app 🎉

@samsja samsja merged commit ae03664 into feat-rewrite-v2 Dec 6, 2022
@samsja samsja deleted the feat-tensor-column-mode branch December 6, 2022 15:55
@JohannesMessner JohannesMessner mentioned this pull request Dec 13, 2022
47 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants