Skip to content

deduplicate code by importing from cellflow#20

Draft
selmanozleyen wants to merge 14 commits into
mainfrom
dedup/reexport-cellflow
Draft

deduplicate code by importing from cellflow#20
selmanozleyen wants to merge 14 commits into
mainfrom
dedup/reexport-cellflow

Conversation

@selmanozleyen

@selmanozleyen selmanozleyen commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

I will note the behaviour changes here:

  • use_gpu flags were never triggered so I removed them
  • I renamed compute_scalar_mmd into compute_scalar_mmd_cf (re-exports cellflow's) + compute_scalar_mmd_sf (scaleflow's 5000-cap / 3-gamma variant, kept explicit). Some paths use compute_scalar_mmd_sf and some _cf. I would rather just have the _cf version but for the metrics a registry mechanism to the main module would fix this problem. Update: I just defaulted to the _cf functions in all cases. Not a big behaviour loss
  • Added SeedAttentionPooling and TokenAttentionPooling features to cellflow so we import them now
  • removed preprocessing code as they were completely duplicate
  • Now working on making registiries for layers to make cellflow more extensible.

Several diverged modules still held byte-identical copies of some classes and
functions (MLPBlock and the other blocks, the metric fns, base callbacks,
ReturnData, etc.). Import those from cellflow and keep only what actually
differs or is new.
It only re-exported _write_predictions, so import it straight from cellflow
at the one use site instead of keeping the file.
…low)

compute_scalar_mmd_cf re-exports cellflow's version; compute_scalar_mmd_sf keeps
scaleflow's 5000-sample-cap variant. Training validation (metric_to_func) uses
cellflow's; existing callers keep the subsampling version.
Metrics differed from cellflow's only in __init__ (use_gpu_optimized /
precision / max_samples_mmd validation); the three compute methods were
byte-identical. Inherit them and override just __init__.
Regular modules now import cellflow symbols only where their own code uses them
(plain imports, no `as X`), and scaleflow.metrics / scaleflow.training export
only scaleflow's own code: the _gpu metrics + compute_scalar_mmd_sf, and the
Metrics subclass / CellFlowTrainer / CallbackRunner / LearningRateMonitor.

Consumers import cellflow's compute_metrics, BaseCallback, ComputationCallback,
PCADecodedMetrics, etc. directly from cellflow. Also dropped the now-dead
metric_to_func / agg_fn_to_func (Metrics inherits cellflow's on_log_iteration).
The GPU path (use_gpu_optimized/precision/max_samples_mmd, metric_to_func_gpu,
the *_gpu functions) was never wired into metric computation — on_log_iteration
always ran on CPU and the callers passed the flag as a no-op. Dropped it all.

With the GPU delta gone the Metrics subclass was identical to cellflow's, so it's
removed too and Metrics is imported straight from cellflow (callers updated).
compute_scalar_mmd_sf stays as scaleflow's own subsampling MMD variant.
scaleflow.external (CFJaxSCVI + the CFJaxVAE re-export) isn't needed here; drop
the package and its tests. The one other reference (a skipped VAE-reconstruction
test) is removed too.
…sing)

Removed the `X as X` re-export lines from data/_data, data/_utils, solvers/utils
and preprocessing/_gene_emb. Symbols that were only re-exported (ReturnData,
BaseDataMixin, _to_list, _flatten_list, ema_update, fetch_*) are gone; those
actually used in-file (GeneInfo, BatchedDataset, _get_esm_collate_fn,
prot_sequence_from_ensembl) are now plain imports. Consumers import straight
from cellflow (_to_list in _preprocessing; ema_update in _otfm/_eqm/_multitask).
…ules

The leaf blocks (BaseModule, MLPBlock, FilmBlock, ResNetBlock,
sinusoidal_time_encoder) are now plain cellflow imports. _get_layers and
_apply_modules can't be imported from cellflow: they build and isinstance-check
SelfAttentionBlock, and scaleflow's SelfAttentionBlock differs (adds ff_dim).
Using cellflow's would build cellflow's ff_dim-less block for self_attention
layers. So they're defined locally, binding scaleflow's SelfAttentionBlock.
cellflow feat/annbatch-loader now carries the ff_dim SelfAttention/SelfAttentionBlock,
multi-layer TokenAttentionPooling and de-duped SeedAttentionPooling, so
networks/_utils drops its local copies (plus _get_layers/_apply_modules) and keeps
only the scaleflow-only AdaLNModulation/AdaLNZeroBlock. Consumers (_velocity_field,
_set_encoders, _phenotype_predictor, model/_recon) import those blocks directly from
cellflow; networks/__init__ exports only scaleflow's own.
The scaleflow-only subsampling MMD variant was the last thing in
scaleflow.metrics, so the whole package goes. Callers now use cellflow's
compute_scalar_mmd directly (dropping the max_samples cap / 3-gamma default),
and "metrics" is removed from the lazy-submodule list.
After moving to cellflow's compute_scalar_mmd, this file only exercised cellflow
functions (cellflow tests those itself), so it no longer covered any scaleflow code.
_pca/_preprocessing/_wknn were byte-identical to cellflow and _gene_emb was a
stale copy (module-top torch import, missing cellflow's pandas>=3 NaN fix), so
scaleflow.preprocessing added nothing. Remove the package + its tests (which only
exercised cellflow's functions) and drop pp/preprocessing from the lazy submodules.
Anything needing it uses cellflow.preprocessing directly.
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.

1 participant