Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/state/_cli/_emb/_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ def load_config_override(config_path: str | None = None):
with torch.no_grad():
with torch.autocast(device_type=device_type, dtype=precision):
for batch in tqdm(dataloader, desc="Processing batches"):
torch.cuda.synchronize()
torch.cuda.empty_cache()
if device_type == "cuda":
torch.cuda.synchronize()
torch.cuda.empty_cache()

# Compute embeddings
_, _, _, emb, ds_emb = model._compute_embedding_for_batch(batch)
Expand Down
3 changes: 2 additions & 1 deletion src/state/emb/nn/eval_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def evaluate_de(model, cfg, device=None, logger=print):
pred_exp = model._predict_exp_for_adata(
tmp_adata, cfg["validations"]["diff_exp"]["dataset_name"], cfg["validations"]["diff_exp"]["obs_pert_col"]
)
torch.cuda.synchronize()
if torch.cuda.is_available():
torch.cuda.synchronize()
Comment on lines +79 to +80
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This synchronization is likely redundant. Since _predict_exp_for_adata returns a result that is subsequently used as a DataFrame or numpy array (e.g., in compute_gene_overlap_cross_pert), the data transfer from the GPU to the host has already performed an implicit synchronization. You may consider removing this block entirely to simplify the code.

de_metrics = compute_gene_overlap_cross_pert(
pred_exp, true_top_genes, k=cfg["validations"]["diff_exp"]["top_k_rank"]
)
Expand Down