Skip to content

feat(v2): tensor column mode#886

Merged
samsja merged 53 commits intofeat-rewrite-v2from
feat-tensor-column-mode
Dec 6, 2022
Merged

feat(v2): tensor column mode#886
samsja merged 53 commits intofeat-rewrite-v2from
feat-tensor-column-mode

Conversation

@samsja
Copy link
Copy Markdown
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():
   ...

Loading
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.

3 participants