Closed marzaidi closed 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.
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!
@marzaidi could you clone and check now with knn_method = 'kd_tree'.
it works now, thank you!
hi! everytime i try to run the command to make predictions, i get an attribute error related to cagra/cuvs.
my command:
the error:
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