Skip to content

KeyError in DataLoader when (tx, belongs, bd).edge_label is missing for some samples #94

Open

Description

@mossishahi

I’m running into a KeyError in the PyTorch Geometric DataLoader when using the package. Some .pt files in my dataset do not include an edge_label in the (tx, belongs, bd) edge store, which leads PyG’s collation logic to crash. It appears that the package generates inconsistent keys across samples in the “processed” dataset, causing the default Batch.from_data_list to fail.

Steps to Reproduce

  1. Create or load a dataset in which some HeteroData objects have (tx, belongs, bd).edge_label while others do not.
  2. Call DataLoader(dataset, batch_size=N).
  3. Attempt to iterate over the loader, e.g., with next(iter(dataloader)).

Activity

  1. andrewmoorman commented on Apr 1, 2025

    @andrewmoorman
    Collaborator

    Thanks for flagging this @mossishahi! I'll take a look.

  2. BioinfoTongLI commented on Jun 9, 2025

    @BioinfoTongLI

    Hello there!
    I think I've got a similar issue with edge_label in the prediction step, which looks like the error message in this one #81 (comment)
    Any ideas what to try? @EliHei2
    both create dataset and train_model finished correctly

    python3 /workspace/segger_dev/src/segger/cli/create_dataset_fast.py \
        --base_dir output-XETG00155__0037475__AT9-BRA-4-FO-4-S51-ii__20241107__134704 \
        --data_dir AT9-BRA-4-FO-4-S51-ii_dataset \
        --sample_type xenium \
        --n_workers 30 \
        --tile_width 120 \
        --tile_height 120 \
        --scrnaseq_file GBM_LEAP_annotations_v2.09_04_24__AT9.h5ad \
        --celltype_column annotation_coarse             --sample_type xenium_v2             --k_bd 3             --dist_bd 15.0             --k_tx 3             --dist_tx 5.0             --neg_sampling_ratio 5.0             --frac 1.0             --val_prob 0
    .1             --test_prob 0.2
    
    python3 /workspace/segger_dev/src/segger/cli/train_model.py \
        --dataset_dir AT6-BRA-3-FO-3-S40-i_dataset \
        --models_dir AT6-BRA-3-FO-3-S40-i_trained_models \
        --sample_tag AT6-BRA-3-FO-3-S40-i \
        --num_workers 30 \
        --batch_size 4 \
        --max_epochs 200 \
        --devices 1 \
        --accelerator cuda \
        --sample_tag AT13-BRA-3-FO-4-S44-ii_scRNA_annotation_coarse             --init_emb 8             --hidden_channels 32             --out_channels 16             --heads 4             --num_mid_layers 3             --batch_size 2             --num_worke
    rs 2             --accelerator cuda             --max_epochs 100             --devices 1             --strategy auto             --precision 32
    

    but not prediction step.

    python3 /workspace/segger_dev/src/segger/cli/predict_fast.py \
        --models_dir AT6-BRA-3-FO-2-S39-ii_trained_models \
        --segger_data_dir AT6-BRA-3-FO-2-S39-ii_dataset \
        --transcripts_file transcripts.parquet \
        --benchmarks_dir AT6-BRA-3-FO-2-S39-ii_benchmarks_dir \
        --num_workers 30 \
        --batch_size 1 \
        --use_cc false \
        --knn_method kd_tree \
            --batch_size 2             --num_workers 2             --model_version 0             --save_tag AT13-BRA-3-FO-4-S44-ii_scRNA_annotation_coarse             --min_transcripts 5             --cell_id_col segger_cell_id             --use_cc false
            --knn_method kd_tree             --file_format anndata             --k_bd 4             --dist_bd 15.0             --k_tx 5             --dist_tx 5.0
    

    cc'ing @krademaker
    And I am using this docker images

    danielunyi42/segger_dev                                                cuda121                   e14dbf486142
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions