Skip to content

babel: fix the atac loss target ordering, and trim peak memory - #1

Merged
benjaminfreyuu merged 3 commits into
benjaminfreyuu:fix/babel-sparse-atacfrom
openproblems-bio:review/babel-sparse-followup
Aug 13, 2026
Merged

babel: fix the atac loss target ordering, and trim peak memory#1
benjaminfreyuu merged 3 commits into
benjaminfreyuu:fix/babel-sparse-atacfrom
openproblems-bio:review/babel-sparse-followup

Conversation

@rcannood

@rcannood rcannood commented Aug 13, 2026

Copy link
Copy Markdown

Hi @benjaminfreyuu !

The sparse rewrite in the PR you created looks good to me :).

Three follow-ups on top of your branch, one commit each, so you can drop any of them independently.

Changes

  • c8fc2fc fix permuted atac target in babel loss. ChromDecoder concatenates its per-chromosome heads in chrom_groups order, but target2_bin was sliced out of y, which is in original var_names order. Those two only agree if the peaks happen to be grouped by chromosome in lexicographic order -- on the 2021 fixture 1499/1500 columns are permuted. Checked against the real PairedDataset/_collate:

    fix   torch.cat(X['x2_per_chrom']) == X_atac[:, chrom_order] : True
    bug   y-sliced target              == X_atac[:, chrom_order] : False
    

    Taking the target from X["x2_per_chrom"], which get_loss already receives, is order-independent so no reindex is needed. It also drops y2 entirely: one less full ATAC copy in RAM, and ~17% off the per-cell densification.

  • 60ec731 free the redundant atac copies before training. At net.fit() five objects each held a full copy of the ATAC non-zeros: both input AnnDatas, X_atac_bin, X_atac_bin_csc, and the per-chromosome slices. The CSC view and the inputs are pure temporaries that never went out of scope. Extract the var_names up front, then del.

  • aa19067 size babel_predict chunks by dense bytes, not cell count. The per-chromosome tensors together span the full peak width and exist on the host and the device at once, so chunk_size = 4096 is ~3.7 GB at 229k peaks -- more than it needs to be on a 16 GB T4 (midgpu). Capping one chunk's dense footprint at 512 MiB gives 586 cells/chunk at 229k peaks, and leaves the 1500-peak fixture at 4096, i.e. unchanged.

Verification

  • viash test src/methods/babel/babel_train/config.vsh.yaml: 1/1 passed
  • viash test src/methods/babel/babel_predict/config.vsh.yaml: 1/1 passed -- the committed output_model.pkl still loads, the bundle keys are unchanged

Not changed

It looks like reindex_to_chrom_groups() is no longer used, and could be removed.

ChromDecoder emits peaks in chrom_groups order, but target2_bin was sliced out of
y in original var_names order.

@benjaminfreyuu benjaminfreyuu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Looks good!

@benjaminfreyuu
benjaminfreyuu merged commit 133e8ae into benjaminfreyuu:fix/babel-sparse-atac Aug 13, 2026
@rcannood
rcannood deleted the review/babel-sparse-followup branch August 14, 2026 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants