You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Sep 9, 2026. It is now read-only.
Error on subindice Embedding type for Torch Tensor moving from GPU to CPU. #1830
from docarray.index.backends.weaviate import EmbeddedOptions
from docarray.index.backends.weaviate import WeaviateDocumentIndex
from typing import Optional
from docarray.typing import AnyEmbedding, NdArrayEmbedding
from pydantic import Field, parse_obj_as
from docarray import DocList, BaseDoc
import numpy as np
import torch
class SubDoc(BaseDoc):
embedding: Optional[AnyEmbedding] = Field(is_embedding=True, n_dim=128)
class MyDoc(BaseDoc):
text: str
subdocs: DocList[SubDoc]
gpu_tensors = [torch.rand(128).to('cuda:2') for i in range(3)]
assert all(t.is_cuda for t in gpu_tensors)
storing them in DocList
data = DocList[MyDoc](
[
MyDoc(text='hello world', subdocs=[SubDoc(embedding=t)]) for t in gpu_tensors
]
)
converting to NdArray on CPU
for doc in data:
doc.subdocs[0].embedding = parse_obj_as(NdArrayEmbedding, doc.subdocs[0].embedding)
assert isinstance(doc.subdocs[0].embedding, np.ndarray) # not on GPU
Activity
JoanFM commentedon Nov 6, 2023
Hey @vincetrep ,
do u have a minimal reproducible code that we can use to debug?
JohannesMessner commentedon Nov 8, 2023
I also cannot reproduce the issue, the following executes without problem:
Sumant02 commentedon Dec 23, 2023
`from docarray.index.backends.weaviate import WeaviateDocumentIndex
doc_index = WeaviateDocumentIndexMyDoc
from docarray.index.backends.weaviate import EmbeddedOptions
from docarray.index.backends.weaviate import WeaviateDocumentIndex
from typing import Optional
from docarray.typing import AnyEmbedding, NdArrayEmbedding
from pydantic import Field, parse_obj_as
from docarray import DocList, BaseDoc
import numpy as np
import torch
class SubDoc(BaseDoc):
embedding: Optional[AnyEmbedding] = Field(is_embedding=True, n_dim=128)
class MyDoc(BaseDoc):
text: str
subdocs: DocList[SubDoc]
dbconfig = WeaviateDocumentIndex.DBConfig(embedded_options=EmbeddedOptions())
doc_index = WeaviateDocumentIndexMyDoc
creating tensors on GPU
gpu_tensors = [torch.rand(128).to('cuda:2') for i in range(3)]
assert all(t.is_cuda for t in gpu_tensors)
storing them in DocList
data = DocList[MyDoc](
[
MyDoc(text='hello world', subdocs=[SubDoc(embedding=t)]) for t in gpu_tensors
]
)
converting to NdArray on CPU
for doc in data:
doc.subdocs[0].embedding = parse_obj_as(NdArrayEmbedding, doc.subdocs[0].embedding)
assert isinstance(doc.subdocs[0].embedding, np.ndarray) # not on GPU
insert into index
doc_index.index(data)
root_docs, sub_docs, scores = doc_index.find_subindex(np.random.rand(128), subindex='subdocs', limit=3)
print(scores)`
@JohannesMessner JohannesMessner