EliHei2 / segger_dev

a cutting-edge cell segmentation model specifically designed for single-molecule resolved spatial omics datasets. It addresses the challenge of accurately segmenting individual cells in complex imaging datasets, leveraging a unique approach based on graph neural networks (GNNs).
https://elihei2.github.io/segger_dev/
MIT License
37 stars 3 forks source link

[BUG] attribute error while making predictions #62

Closed marzaidi closed 1 week ago

marzaidi commented 1 week ago

hi! everytime i try to run the command to make predictions, i get an attribute error related to cagra/cuvs.

my command:

dm = SeggerDataModule(
    data_dir=segger_data_dir,
    batch_size=2,
    num_workers=0,
)

dm.setup()

model_version = 0
model_path = model_dir / "lightning_logs" / f"version_{model_version}"
model = load_model(model_path/ "checkpoints")

receptive_field = {'k_bd': 4, 'dist_bd': 12, 'k_tx': 15, 'dist_tx': 3}

segment(
    model,
    dm,
    save_dir='benchmarks',
    seg_tag='segger_embedding_1001',
    transcript_file='data_xenium/transcripts.parquet',
    receptive_field=receptive_field,
    min_transcripts=5,
    cell_id_col='segger_cell_id',
    use_cc=False,
    knn_method='cuda',
    verbose=True,
)

the error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File [~/segger_dev/src/segger/data/utils.py:413](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/~/segger_dev/src/segger/data/utils.py#line=412), in get_edge_index_cuda(coords_1, coords_2, k, dist, metric, nn_descent_niter)
    412 try:
--> 413     index = cagra.build(index_params, cp_coords_1)
    414 except AttributeError:

AttributeError: module 'cuvs.neighbors.cagra' has no attribute 'build'

During handling of the above exception, another exception occurred:

CuvsException                             Traceback (most recent call last)
Cell In[44], line 15
     11 model = load_model(model_path [/](https://ood-2.ai.lrz.de/) "checkpoints")
     13 receptive_field = {'k_bd': 4, 'dist_bd': 12, 'k_tx': 15, 'dist_tx': 3}
---> 15 segment(
     16     model,
     17     dm,
     18     save_dir='benchmarks',
     19     seg_tag='segger_embedding_1001',
     20     transcript_file='[/dss/dssfs02/lwp-dss-0001/pn57fo/pn57fo-dss-0000/mariam/copies/transcripts.parquet](https://ood-2.ai.lrz.de/dss/dssfs02/lwp-dss-0001/pn57fo/pn57fo-dss-0000/mariam/copies/transcripts.parquet)',
     21     receptive_field=receptive_field,
     22     min_transcripts=5,
     23     cell_id_col='cell_id',
     24     use_cc=False,
     25     knn_method='cuda',
     26     verbose=True,
     27 )

File [~/segger_dev/src/segger/prediction/predict_parquet.py:516](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/~/segger_dev/src/segger/prediction/predict_parquet.py#line=515), in segment(model, dm, save_dir, seg_tag, transcript_file, score_cut, use_cc, file_format, save_transcripts, save_anndata, save_cell_masks, receptive_field, knn_method, verbose, gpu_ids, **anndata_kwargs)
    514         gpu_id = random.choice(gpu_ids)
    515         # Call predict_batch for each batch
--> 516         predict_batch(
    517             model,
    518             batch,
    519             score_cut,
    520             receptive_field,
    521             use_cc=use_cc,
    522             knn_method=knn_method,
    523             edge_index_save_path=edge_index_save_path,
    524             output_ddf_save_path=output_ddf_save_path,
    525             gpu_id=gpu_id,
    526         )
    528 if verbose:
    529     elapsed_time = time() - step_start_time

File [~/segger_dev/src/segger/prediction/predict_parquet.py:308](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/~/segger_dev/src/segger/prediction/predict_parquet.py#line=307), in predict_batch(lit_segger, batch, score_cut, receptive_field, use_cc, knn_method, edge_index_save_path, output_ddf_save_path, gpu_id)
    304 assignments = {"transcript_id": transcript_id}
    306 if len(batch["bd"].pos) >= 10:
    307     # Step 1: Compute similarity scores between 'tx' (transcripts) and 'bd' (boundaries)
--> 308     scores = get_similarity_scores(
    309         lit_segger.model, batch, "tx", "bd", receptive_field, knn_method=knn_method, gpu_id=gpu_id
    310     )
    311     torch.cuda.empty_cache()
    313     # Convert sparse matrix to dense format (on GPU)

File [~/segger_dev/src/segger/prediction/predict_parquet.py:218](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/~/segger_dev/src/segger/prediction/predict_parquet.py#line=217), in get_similarity_scores(model, batch, from_type, to_type, receptive_field, knn_method, gpu_id)
    215 shape = batch[from_type].x.shape[0], batch[to_type].x.shape[0]
    217 # Compute edge indices using knn method (still on GPU)
--> 218 edge_index = get_edge_index(
    219     batch[to_type].pos[:, :2],  # 'tx' positions
    220     batch[from_type].pos[:, :2],  # 'bd' positions
    221     k=receptive_field[f"k_{to_type}"],
    222     dist=receptive_field[f"dist_{to_type}"],
    223     method=knn_method,
    224 )
    226 # Convert to dense adjacency matrix (on GPU)
    227 edge_index = coo_to_dense_adj(edge_index.T, num_nodes=shape[0], num_nbrs=receptive_field[f"k_{to_type}"])

File [~/segger_dev/src/segger/data/utils.py:296](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/~/segger_dev/src/segger/data/utils.py#line=295), in get_edge_index(coords_1, coords_2, k, dist, method, gpu, workers)
    293     return get_edge_index_faiss(coords_1, coords_2, k=k, dist=dist, gpu=gpu)
    294 elif method == "cuda":
    295     # pass
--> 296     return get_edge_index_cuda(coords_1, coords_2, k=k, dist=dist)
    297 else:
    298     msg = f"Unknown method {method}. Valid methods include: 'kd_tree', " "'faiss', and 'cuda'."

File [~/segger_dev/src/segger/data/utils.py:415](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/~/segger_dev/src/segger/data/utils.py#line=414), in get_edge_index_cuda(coords_1, coords_2, k, dist, metric, nn_descent_niter)
    413     index = cagra.build(index_params, cp_coords_1)
    414 except AttributeError:
--> 415     index = cagra.build_index(index_params, cp_coords_1)
    416 # Perform search to get distances and indices (still in CuPy)
    417 D, I = cagra.search(search_params, index, cp_coords_2, k)

File resources.pyx:110, in cuvs.common.resources.auto_sync_resources.wrapper()

File cagra.pyx:199, in cuvs.neighbors.cagra.cagra.build_index()

File cagra.pyx:200, in cuvs.neighbors.cagra.cagra.build_index()

File exceptions.pyx:37, in cuvs.common.exceptions.check_cuvs()

CuvsException: CUDA error encountered at: file=[/__w/cuvs/cuvs/python/cuvs/build/cp310-cp310-manylinux_2_17_x86_64/_deps/raft-src/cpp/include/raft/linalg/detail/coalesced_reduction-inl.cuh](https://ood-2.ai.lrz.de/__w/cuvs/cuvs/python/cuvs/build/cp310-cp310-manylinux_2_17_x86_64/_deps/raft-src/cpp/include/raft/linalg/detail/coalesced_reduction-inl.cuh) line=97: call='cudaPeekAtLastError()', Reason=cudaErrorNoKernelImageForDevice:no kernel image is available for execution on the device
Obtained 63 stack frames
#1 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/neighbors/cagra/../../libcuvs.so](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/libcuvs.so): raft::cuda_error::cuda_error(std::string const&) +0x14b [0x7f0c43ec479b]
#2 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/neighbors/cagra/../../libcuvs.so](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/libcuvs.so): void raft::linalg::detail::coalescedReduction<float, float, long, raft::sq_op, raft::add_op, raft::identity_op>(float*, float const*, long, long, float, CUstream_st*, bool, raft::sq_op, raft::add_op, raft::identity_op) +0x1706 [0x7f0c44025eb6]
#3 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/neighbors/cagra/../../libcuvs.so](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/libcuvs.so)(+0x21c8aff) [0x7f0c445fbaff]
#4 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/neighbors/cagra/../../libcuvs.so](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/libcuvs.so): raft::neighbors::ivf_pq::index<long> raft::neighbors::ivf_pq::detail::build<float, long>(raft::resources const&, raft::neighbors::ivf_pq::index_params const&, float const*, long, unsigned int) +0x533 [0x7f0c44603e83]
#5 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/neighbors/cagra/../../libcuvs.so](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/libcuvs.so): raft::neighbors::ivf_pq::index<long> raft::neighbors::ivf_pq::build<float, long>(raft::resources const&, raft::neighbors::ivf_pq::index_params const&, float const*, long, unsigned int) +0xa [0x7f0c44605aba]
#6 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/neighbors/cagra/../../libcuvs.so](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/libcuvs.so): raft::runtime::neighbors::cagra::build(raft::resources const&, raft::neighbors::cagra::index_params const&, std::experimental::mdspan<float const, std::experimental::extents<long, 18446744073709551615ul, 18446744073709551615ul>, std::experimental::layout_right, raft::host_device_accessor<std::experimental::default_accessor<float const>, (raft::memory_type)2> >) +0x991 [0x7f0c440b0ba1]
#7 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/neighbors/cagra/../../libcuvs.so](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/libcuvs.so): raft::runtime::neighbors::cagra::build_device(raft::resources const&, raft::neighbors::cagra::index_params const&, std::experimental::mdspan<float const, std::experimental::extents<long, 18446744073709551615ul, 18446744073709551615ul>, std::experimental::layout_right, raft::host_device_accessor<std::experimental::default_accessor<float const>, (raft::memory_type)2> >, raft::neighbors::cagra::index<float, unsigned int>&) +0x3e [0x7f0c440b28ee]
#8 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/neighbors/cagra/../../libcuvs.so](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/libcuvs.so): cuvs::neighbors::cagra::build_device(raft::resources const&, cuvs::neighbors::cagra::index_params const&, std::experimental::mdspan<float const, std::experimental::extents<long, 18446744073709551615ul, 18446744073709551615ul>, std::experimental::layout_right, raft::host_device_accessor<std::experimental::default_accessor<float const>, (raft::memory_type)2> >, cuvs::neighbors::cagra::index<float, unsigned int>&) +0x80 [0x7f0c43f0a440]
#9 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/neighbors/cagra/../../libcuvs_c.so](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/libcuvs_c.so): cuvsCagraBuild +0x40f [0x7f0c7fb153ff]
#10 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/neighbors/cagra/cagra.cpython-310-x86_64-linux-gnu.so](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/neighbors/cagra/cagra.cpython-310-x86_64-linux-gnu.so)(+0x11a50) [0x7f0d63275a50]
#11 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/lib/python3.10/site-packages/pyarrow/lib.cpython-310-x86_64-linux-gnu.so](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/lib/python3.10/site-packages/pyarrow/lib.cpython-310-x86_64-linux-gnu.so)(+0x1284e2) [0x7f0d9cd524e2]
#12 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/common/resources.cpython-310-x86_64-linux-gnu.so](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/lib/python3.10/site-packages/cuvs/common/resources.cpython-310-x86_64-linux-gnu.so)(+0xb5e0) [0x7f0d41c585e0]
#13 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyObject_MakeTpCall +0x25b [0x4f657b]
#14 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x53ee [0x4f275e]
#15 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyFunction_Vectorcall +0x6f [0x4fcf3f]
#16 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x13b2 [0x4ee722]
#17 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyFunction_Vectorcall +0x6f [0x4fcf3f]
#18 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x13b2 [0x4ee722]
#19 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyFunction_Vectorcall +0x6f [0x4fcf3f]
#20 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x13b2 [0x4ee722]
#21 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyFunction_Vectorcall +0x6f [0x4fcf3f]
#22 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x13b2 [0x4ee722]
#23 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyFunction_Vectorcall +0x6f [0x4fcf3f]
#24 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x13b2 [0x4ee722]
#25 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x5924f2]
#26 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): PyEval_EvalCode +0x87 [0x592437]
#27 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x59992d]
#28 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x4fd124]
#29 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x31f [0x4ed68f]
#30 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x59bf49]
#31 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x1b68 [0x4eeed8]
#32 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x59bf49]
#33 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x1b68 [0x4eeed8]
#34 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x59bf49]
#35 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x5b0076]
#36 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x50732f]
#37 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x731 [0x4edaa1]
#38 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyFunction_Vectorcall +0x6f [0x4fcf3f]
#39 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x31f [0x4ed68f]
#40 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyFunction_Vectorcall +0x6f [0x4fcf3f]
#41 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x731 [0x4edaa1]
#42 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x50832e]
#43 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): PyObject_Call +0xb8 [0x508cd8]
#44 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x2de4 [0x4f0154]
#45 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x50832e]
#46 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x13b2 [0x4ee722]
#47 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x59bf49]
#48 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x1b68 [0x4eeed8]
#49 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x59bf49]
#50 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x1b68 [0x4eeed8]
#51 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x59bf49]
#52 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x1b68 [0x4eeed8]
#53 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x59bf49]
#54 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x1b68 [0x4eeed8]
#55 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x59bf49]
#56 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x1b68 [0x4eeed8]
#57 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x59bf49]
#58 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/lib/python3.10/lib-dynload/_asyncio.cpython-310-x86_64-linux-gnu.so](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/lib/python3.10/lib-dynload/_asyncio.cpython-310-x86_64-linux-gnu.so)(+0x7d5d) [0x7f0dd87c6d5d]
#59 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x4fc56b]
#60 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x61a0d1]
#61 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x4b9ec9]
#62 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python)() [0x4f4eeb]
#63 in [/dss/dsshome1/0C/go76saz2/miniconda3/envs/segger/bin/python](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/miniconda3/envs/segger/bin/python): _PyEval_EvalFrameDefault +0x5b80 [0x4f2ef0]

python: 3.10.15 OS: Linux cm2login1 4.12.14-197.108-default #1 SMP Tue Mar 1 18:11:35 UTC 2022 (2b1bf36) x86_64 x86_64 x86_64 GNU/Linux

EliHei2 commented 1 week ago

Hi! We're aware of the hardships of working with cuvs stuff, hopefully both cuvs and segger's usage of it are gonna be more stable in the next releases. could you let me know what's your version of cuvs?

In the meanwhile you could set knn_method='kd_tree'. Also I recommend you reclone the package, it seems you have the previous version now.

marzaidi commented 1 week ago

thanks for your help! i have recloned the package.

my version of cuvs:

cuda-python              12.6.0
cupy-cuda12x             13.3.0
cuvs-cu12                24.4.0

now i am getting a type error:

from segger.prediction.predict_parquet import segment, load_model

dm = SeggerDataModule(
    data_dir=segger_data_dir,
    batch_size=2,
    num_workers=0,
)

dm.setup()

model_version = 0
model_path = models_dir / "lightning_logs" / f"version_{model_version}"
model = load_model(model_path / "checkpoints")

# Receptive field configuration
receptive_field = {'k_bd': 4, 'dist_bd': 12, 'k_tx': 15, 'dist_tx': 3}

segment(
    model,
    dm,
    save_dir='benchmarks',
    seg_tag='segger_embedding_1001',
    transcript_file= Path('xenium_data_dir/transcripts.parquet'),
    receptive_field=receptive_field,
    min_transcripts=5,
    cell_id_col='cell_id',
    use_cc=False,
    knn_method='kd_tree',
    verbose=True,
)

error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[37], line 17
     14 # Receptive field configuration
     15 receptive_field = {'k_bd': 4, 'dist_bd': 12, 'k_tx': 15, 'dist_tx': 3}
---> 17 segment(
     18     model,
     19     dm,
     20     save_dir='benchmarks',
     21     seg_tag='segger_embedding_1001',
     22     transcript_file= Path('xenium_data_dir[/transcripts.parquet](https://ood-2.ai.lrz.de/transcripts.parquet)'),
     23     receptive_field=receptive_field,
     24     min_transcripts=5,
     25     cell_id_col='cell_id',
     26     use_cc=False,
     27     knn_method='kd_tree',
     28     verbose=True,
     29 )

File [~/segger_dev/src/segger/prediction/predict_parquet.py:516](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/~/segger_dev/src/segger/prediction/predict_parquet.py#line=515), in segment(model, dm, save_dir, seg_tag, transcript_file, score_cut, use_cc, file_format, save_transcripts, save_anndata, save_cell_masks, receptive_field, knn_method, verbose, gpu_ids, **anndata_kwargs)
    514         gpu_id = random.choice(gpu_ids)
    515         # Call predict_batch for each batch
--> 516         predict_batch(
    517             model,
    518             batch,
    519             score_cut,
    520             receptive_field,
    521             use_cc=use_cc,
    522             knn_method=knn_method,
    523             edge_index_save_path=edge_index_save_path,
    524             output_ddf_save_path=output_ddf_save_path,
    525             gpu_id=gpu_id,
    526         )
    528 if verbose:
    529     elapsed_time = time() - step_start_time

File [~/segger_dev/src/segger/prediction/predict_parquet.py:308](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/~/segger_dev/src/segger/prediction/predict_parquet.py#line=307), in predict_batch(lit_segger, batch, score_cut, receptive_field, use_cc, knn_method, edge_index_save_path, output_ddf_save_path, gpu_id)
    304 assignments = {"transcript_id": transcript_id}
    306 if len(batch["bd"].pos) >= 10:
    307     # Step 1: Compute similarity scores between 'tx' (transcripts) and 'bd' (boundaries)
--> 308     scores = get_similarity_scores(
    309         lit_segger.model, batch, "tx", "bd", receptive_field, knn_method=knn_method, gpu_id=gpu_id
    310     )
    311     torch.cuda.empty_cache()
    313     # Convert sparse matrix to dense format (on GPU)

File [~/segger_dev/src/segger/prediction/predict_parquet.py:218](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/~/segger_dev/src/segger/prediction/predict_parquet.py#line=217), in get_similarity_scores(model, batch, from_type, to_type, receptive_field, knn_method, gpu_id)
    215 shape = batch[from_type].x.shape[0], batch[to_type].x.shape[0]
    217 # Compute edge indices using knn method (still on GPU)
--> 218 edge_index = get_edge_index(
    219     batch[to_type].pos[:, :2],  # 'tx' positions
    220     batch[from_type].pos[:, :2],  # 'bd' positions
    221     k=receptive_field[f"k_{to_type}"],
    222     dist=receptive_field[f"dist_{to_type}"],
    223     method=knn_method,
    224 )
    226 # Convert to dense adjacency matrix (on GPU)
    227 edge_index = coo_to_dense_adj(edge_index.T, num_nodes=shape[0], num_nbrs=receptive_field[f"k_{to_type}"])

File [~/segger_dev/src/segger/data/utils.py:291](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/~/segger_dev/src/segger/data/utils.py#line=290), in get_edge_index(coords_1, coords_2, k, dist, method, gpu, workers)
    276 """
    277 Computes edge indices using various methods (KD-Tree, FAISS, RAPIDS::cuvs+cupy (cuda)).
    278 
   (...)
    288     torch.Tensor: Edge indices.
    289 """
    290 if method == "kd_tree":
--> 291     return get_edge_index_kdtree(coords_1, coords_2, k=k, dist=dist, workers=workers)
    292 elif method == "faiss":
    293     return get_edge_index_faiss(coords_1, coords_2, k=k, dist=dist, gpu=gpu)

File [~/segger_dev/src/segger/data/utils.py:317](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/~/segger_dev/src/segger/data/utils.py#line=316), in get_edge_index_kdtree(coords_1, coords_2, k, dist, workers)
    302 def get_edge_index_kdtree(
    303     coords_1: np.ndarray, coords_2: np.ndarray, k: int = 5, dist: int = 10, workers: int = 1
    304 ) -> torch.Tensor:
    305     """
    306     Computes edge indices using KDTree.
    307 
   (...)
    315         torch.Tensor: Edge indices.
    316     """
--> 317     tree = cKDTree(coords_1)
    318     d_kdtree, idx_out = tree.query(coords_2, k=k, distance_upper_bound=dist, workers=workers)
    319     valid_mask = d_kdtree < dist

File _ckdtree.pyx:557, in scipy.spatial._ckdtree.cKDTree.__init__()

File [~/miniconda3/envs/segger/lib/python3.10/site-packages/torch/_tensor.py:1151](https://ood-2.ai.lrz.de/node/p100-001.ai.lrz.de/8972/lab/tree/~/miniconda3/envs/segger/lib/python3.10/site-packages/torch/_tensor.py#line=1150), in Tensor.__array__(self, dtype)
   1149     return self.numpy()
   1150 else:
-> 1151     return self.numpy().astype(dtype, copy=False)

TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

i noticed someone else opened an issue about the same error, but the solution there doesn't work for me. thanks in advance!

EliHei2 commented 1 week ago

@marzaidi could you clone and check now with knn_method = 'kd_tree'.

marzaidi commented 1 week ago

it works now, thank you!