Compare commits

...
3 Commits
Author SHA1 Message Date
Tom Kasper 18c420d56a Bump custom_models to cda6cfd; pin torch env refs to it
Submodule adds the store out_dir mkdir fix and TrainConfig.grad_accum
(effective batch 256 via micro-batching on small GPUs). The env yamls
must point at the same commit or fresh conda builds get code that fails
on new store dirs and cannot honour --grad-accum.
2026-11-05 23:16:07 +01:00
Tom Kasper aa79bc02fb Train with gradient accumulation + Triton-native-JIT workaround on 16 GB GPUs
Effective batch stays the spec's 256; --grad-accum splits it into
micro-batches sized from measured bf16 fwd+bwd peaks on the RTX 4060 Ti
(GRAD_ACCUM table per ladder point, fallback 32). train/test shells also
export TORCH_DISABLE_NATIVE_JIT=1 (torch 2.13 Triton native ops cannot
build in the conda env: no CUDA headers) and expandable_segments to
fight fragmentation. Requires custom_models grad_accum support.
2026-11-05 23:13:23 +01:00
Tom Kasper 523667afac Use the lr:hq aligner preset everywhere (R10.4.1 / V14 chemistry)
Single config knob align_preset (default lr:hq) now drives all three
aligner invocations: dorado's native --mm2-opts, the minimap2 .mmi index
build (index options are stored in the .mmi and would otherwise override
the mapping preset) and the rocm fallback chain. Replaces the map-ont
default that kept reappearing from the design doc's labelling section.
2026-10-16 20:11:00 +01:00
7 changed files with 44 additions and 8 deletions
+5 -2
View File
@@ -17,8 +17,11 @@ hac_min_q: 9 # "" or 0 to disable
fast_model_name: "dna_r10.4.1_e8.2_400bps_fast@v5.2.0" # v2 alignment baseline
fast_benchmarks_file: "" # add path if available
fast_min_q: 8 # "" or 0 to disable
minimap_extra: "-N 10" # minimap2 secondary alignments kept for label-QC visibility (rocm branch)
dorado_mm2_opts: "-x map-ont -N 10" # mm2 options for dorado's native aligner (--reference; overrides the lr:hq default)
minimap_extra: "-N 10" # secondary alignments kept for label-QC visibility
# Alignment preset — single knob for every aligner invocation (dorado --mm2-opts,
# the minimap2 index build and the rocm fallback chain). R10.4.1 / V14 chemistry
# data: lr:hq per ONT's recommendation (map-ont is the pre-V14 default).
align_preset: "lr:hq"
# dataset wiring
pod5_dataset: "nomiss_96BC_P2I_SUP_2026"
+1 -1
View File
@@ -15,4 +15,4 @@ dependencies:
# copies env yamls into .snakemake/conda/, where relative paths
# break. Bump the ref together with the `custom_models` submodule
# pointer (git submodule update --remote custom_models).
- git+ssh://git@git.tk-ai.eu/Tom/eDNA_Stream_E01_custom_models.git@87c6427
- git+ssh://git@git.tk-ai.eu/Tom/eDNA_Stream_E01_custom_models.git@cda6cfd
+1 -1
View File
@@ -14,4 +14,4 @@ dependencies:
# copies env yamls into .snakemake/conda/, where relative paths
# break. Bump the ref together with the `custom_models` submodule
# pointer (git submodule update --remote custom_models).
- git+ssh://git@git.tk-ai.eu/Tom/eDNA_Stream_E01_custom_models.git@87c6427
- git+ssh://git@git.tk-ai.eu/Tom/eDNA_Stream_E01_custom_models.git@cda6cfd
+2 -2
View File
@@ -146,7 +146,7 @@ if GPU_STACK == "cuda":
benchmarking=get_benchmarking_file,
min_q=get_qscore,
kit_flag=get_kit_flag,
mm2_opts=config["dorado_mm2_opts"],
mm2_opts=f"-x {config['align_preset']} {config['minimap_extra']}",
shell:
"""
dorado basecaller --models-directory {config[dorado_model_dir]} --emit-cram {params.benchmarking} {params.min_q} {params.kit_flag} --reference {input.ref} --mm2-opts "{params.mm2_opts}" {params.dorado_model} {input.pod5} > {output}
@@ -194,7 +194,7 @@ elif GPU_STACK == "rocm":
"../envs/minimap.yaml"
shell:
"""
minimap2 -ax map-ont {params.minimap_extra} -t {threads} {input.ref} {input.fastq} > {output}
minimap2 -a -x {config[align_preset]} {params.minimap_extra} -t {threads} {input.ref} {input.fastq} > {output}
"""
rule convert_sam_to_bam:
+33
View File
@@ -123,6 +123,31 @@ def train_run_id(w):
return f"{w.arch}_{fmt_budget(w.budget)}_s{w.stride}_g{n}{spec['suffix']}"
# Effective optimiser batch stays the spec's 256; --grad-accum splits it into
# micro-batches that fit the 16 GB RTX 4060 Ti. Values from measured bf16
# fwd+bwd peaks (2026-11-04, this machine): peak(32) per point scaled with a
# 1.3 safety factor to keep every run under ~8 GiB. Unknown combinations fall
# back to 32 micro-steps of 8 (safe for the largest lattice shapes).
GRAD_ACCUM = {
("cnn", "1000000", "4"): 4,
("cnn", "1000000", "8"): 1,
("cnn", "5000000", "4"): 8,
("cnn", "5000000", "8"): 4,
("cnn", "20000000", "4"): 16,
("cnn", "20000000", "8"): 8,
("linatt", "1000000", "4"): 4,
("linatt", "1000000", "8"): 1,
("linatt", "5000000", "4"): 16,
("linatt", "5000000", "8"): 8,
("linatt", "20000000", "4"): 32,
("linatt", "20000000", "8"): 16,
}
def train_grad_accum(w):
return GRAD_ACCUM.get((str(w.arch), str(w.budget), str(w.stride)), 32)
# ---------------------------------------------------------------------------
# labels + signal stores
# ---------------------------------------------------------------------------
@@ -205,6 +230,10 @@ rule build_store_windows_ablation:
# ---------------------------------------------------------------------------
# training (Stage-A ladder, control, Stage-B variants)
# ---------------------------------------------------------------------------
# TORCH_DISABLE_NATIVE_JIT=1: torch 2.13 dispatches some matmul/einsum
# backwards to Triton-compiled native ops that cannot build in this conda env
# (no CUDA headers) -> fall back to cuBLAS. expandable_segments fights
# fragmentation on the 16 GB card.
rule train_probe:
input:
store=lambda w: train_spec(w)["store"],
@@ -220,17 +249,20 @@ rule train_probe:
stage=lambda w: train_spec(w)["stage"],
flags=lambda w: train_spec(w)["flags"],
genera_flag=lambda w: train_spec(w)["genera_flag"],
grad_accum=train_grad_accum,
threads: 8
resources:
gpu=1
conda: config["torch_env"]
shell:
"""
TORCH_DISABLE_NATIVE_JIT=1 PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True \
python -m custom_models train \
--arch {wildcards.arch} \
--budget {wildcards.budget} \
--stride {wildcards.stride} \
--budget-tol {config[budget_tolerance]} \
--grad-accum {params.grad_accum} \
{params.flags} {params.genera_flag} \
--store {input.store} \
--out-dir {params.run_dir} \
@@ -257,6 +289,7 @@ rule test_probe:
conda: config["torch_env"]
shell:
"""
TORCH_DISABLE_NATIVE_JIT=1 PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True \
python -m custom_models test \
--run-dir {params.run_dir} \
--trap-store {input.trap_store} \
+1 -1
View File
@@ -80,5 +80,5 @@ rule create_minimap_index:
"../envs/minimap.yaml"
shell:
"""
minimap2 -x map-ont -t {threads} -d {output} {input}
minimap2 -x {config[align_preset]} -t {threads} -d {output} {input}
"""