Repository navigation
[models] Defer backend errors from attn_gym's lazily resolved exports - #5565
Conversation
|
|
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
|
@claude review |
|
Claude finished @tianyu-l's task in 1m 24s —— View job Review: Defer backend errors from attn_gym's lazily resolved exports
The root cause is right. #5467 only caught a I wasn't able to run the tests or pre-commit in this environment because the commands need approval, so everything here comes from reading the code. I did check every entry in 1. attn_gym's install hint is dropped from the deferred error (
|
Thanks @tianyu-l for the review. Pushed a follow up commit addressing it:
Verified on macOS 15 with attn-gym 0.0.17 and no cutlass/triton, |
|
@claude review again |
|
Claude finished @tianyu-l's task in 46s —— View job Re-review: Defer backend errors from attn_gym's lazily resolved exports
The follow-up commit (d990ef5) fixes everything from the last review. I didn't find any new issues, so this looks ready to merge to me. I couldn't run pytest or pre-commit here because those commands need approval in this environment. Everything below comes from reading the code. If you want CI to back this up, a maintainer still has to approve the Previous findings
Fresh pass on the facade
Tests
Nit (optional)
SummaryLGTM. The fixes are minimal, they match the suggestions, and the tests have been updated to cover them. |
### Summary `paged_stash_memory_policy.py` imported `triton` at module level, and `graph_trainer.trainer` imports it through `graph_pp/pipeline.py -> graph_builder.py -> graph_builder_utils.py`. On a platform without Triton wheels (macOS, CPU only) `GraphTrainer` therefore did not import, and three CPU test modules did not collect: `tests/unit_tests/cpu/test_trainer.py`, `config/test_config_validation.py`, `config/test_cuda_graph_validation_config.py` (noted as the remaining collection errors in #5565, now merged). - The two Megatron Core kernels (`paged_stash_copy_kernel`, `paged_stash_pop_kernel`) and `GLOBAL_BLOCK_SIZE` move verbatim, with their "copied from Megatron Core 0.19.0, do not clean up" header, into `paged_stash_kernels.py`. Nothing outside `PagedStashBuffer.launch_copy` / `launch_pop` referenced them (they were in `__all__`, which no longer lists them). - `launch_copy` and `launch_pop` import the kernel module at launch. The policy module imports everywhere, a launch on a machine without Triton raises Python's own `ModuleNotFoundError: No module named 'triton'`, and the kernels can only run on CUDA anyway. - No change where Triton is installed: the same kernels run from the same launch sites, imported once from `sys.modules` after the first launch. ### Test plan New `torchtitan/experiments/graph_trainer/tests/test_optional_imports.py`, in a subprocess that blocks `triton` on `sys.meta_path`, `GraphTrainer` and `paged_stash_memory_policy` import with `triton` never loaded, importing `paged_stash_kernels` and calling `PagedStashBuffer.launch_copy` raise `ModuleNotFoundError` with `name == "triton"`. Fails on main (the policy import raises), passes with this change. On macOS 15 (no Triton), torch 2.16.0.dev20261022 CPU, torch_checkpointing 0.1.1, on main 3ed5aa9 (with #5565 merged): - `pytest tests/unit_tests/cpu --collect-only`, 3 errors / 1847 tests collected on main (`test_trainer.py`, `config/test_config_validation.py`, `config/test_cuda_graph_validation_config.py`, all the Triton import) -> 0 errors / 1926 tests collected with this change. - `tests/unit_tests/cpu/test_trainer.py`, `config/test_config_validation.py`, `config/test_cuda_graph_validation_config.py`, 79 passed. - The new test, 1 passed. - pre commit on the three files passes every hook except pyrefly, which reports the `import triton` lines of the new module (no Triton locally) and diagnostics that pre date this change in `paged_stash_memory_policy.py`. The GPU paged stash tests (`torchtitan/experiments/graph_trainer/tests/test_paged_stash.py`) import only the policy module's public names, which are unchanged, I could not run them here (no CUDA).
Branch was 124 commits behind main; attn_gym.py predated 3ed5aa9 which defers cutlass/triton ImportError from attn_gym.linear._lazy (causal_conv1d via cute.py:26) to a _MissingKernel placeholder. Without it, any import of torchtitan.models.common — including torchtitan.experiments.ezpz.agpt.config_registry via agpt/__init__.py:36 — hard-fails on macOS where attn-gym 0.0.17 is installed but cutlass is not. Aurora never hit it (cutlass available on compute). Bring file verbatim from origin/main.
Branch was 124 commits behind main; attn_gym.py predated 3ed5aa9 which defers backend ImportError from attn_gym.linear._lazy (causal_conv1d via cute.py:26 import cutlass) to a _MissingKernel placeholder. Without it, any import of torchtitan.models.common — including torchtitan.experiments.ezpz.agpt.config_registry via agpt/__init__.py:36 — hard-fails on macOS where attn-gym 0.0.17 is installed but cutlass is absent. Aurora (Intel XPU via aurora_frameworks-2026.1.0 / oneAPI, no CUDA) was never affected — its XPU path does not hit cutlass the same way and all 4B/10B jobs reached Training starts at step 1. Bring file verbatim from origin/main.
30B 8N selective (9053611, E 143) hits the same _set_storage_data_ptr_access_error_msg bomb as full: _placeholder.py:101 torch._C._set_storage_data_ptr_access_error_msg AttributeError: module torch._C has no attribute ... Both DefaultActivationRematConfig and FullActivationRematConfig go through torch_remat 0.2.0 on aurora_frameworks-2026.1.0 (torch 2.13). 30B stays infeasible until frameworks pins a compatible torch_remat. Keep 30B on none and document the failure; keep attn_gym pytorch#5565 sync.
…is_missing_kernel in callers Sourcery flagged that only attn_gym.py was synced from main (pytorch#5565); its callers still did bare require_attn_gym()/identity checks that TypeError'd or leaked placeholders into SPMD registration when cutlass/triton absent. Pull the companion 4 files from main and add a compat shim for the renamed prepare_cp_linear_attention_metadata. Co-Authored-By: internal-model
…30B infeasible on current frameworks (#76) * fix(ezpz): gate 30B v2 4K to selective remat Full (torch_remat 0.2.0 on aurora_frameworks-2026.1.0) hits _set_storage_data_ptr_access_error_msg bomb; none OOMs at 30B even at 8N (9053526 CCL scaleout_device_buf malloc fail). Selective (DefaultActivationRematConfig, model-declared regions) uses a different torch_remat path and may fit within XPU memory. 4B/10B stay on none (already finite-loss). * fix(ezpz): sync attn_gym lazy-export deferral from main (pytorch#5565) Branch was 124 commits behind main; attn_gym.py predated 3ed5aa9 which defers backend ImportError from attn_gym.linear._lazy (causal_conv1d via cute.py:26 import cutlass) to a _MissingKernel placeholder. Without it, any import of torchtitan.models.common — including torchtitan.experiments.ezpz.agpt.config_registry via agpt/__init__.py:36 — hard-fails on macOS where attn-gym 0.0.17 is installed but cutlass is absent. Aurora (Intel XPU via aurora_frameworks-2026.1.0 / oneAPI, no CUDA) was never affected — its XPU path does not hit cutlass the same way and all 4B/10B jobs reached Training starts at step 1. Bring file verbatim from origin/main. * Revert "fix(ezpz): gate 30B v2 4K to selective remat" 30B 8N selective (9053611, E 143) hits the same _set_storage_data_ptr_access_error_msg bomb as full: _placeholder.py:101 torch._C._set_storage_data_ptr_access_error_msg AttributeError: module torch._C has no attribute ... Both DefaultActivationRematConfig and FullActivationRematConfig go through torch_remat 0.2.0 on aurora_frameworks-2026.1.0 (torch 2.13). 30B stays infeasible until frameworks pins a compatible torch_remat. Keep 30B on none and document the failure; keep attn_gym pytorch#5565 sync. * feat(ezpz): agpt-v2 4B/10B 4K configs streaming full raw olmo-mix-1124 Add agpt_v2_{4b,10b}_4k_olmo_mix, which stream the raw olmo-mix-1124 JSON shards listed in $AGPT_V2_DATA_MANIFEST through the Grain HF streaming source, and build_olmo_mix_manifest.py, which sizes that list to a multiple of the DP world size so split_dataset_by_node assigns whole files per rank. * fix(ezpz): complete attn_gym deferral sync — wire require_attn_gym + is_missing_kernel in callers Sourcery flagged that only attn_gym.py was synced from main (pytorch#5565); its callers still did bare require_attn_gym()/identity checks that TypeError'd or leaked placeholders into SPMD registration when cutlass/triton absent. Pull the companion 4 files from main and add a compat shim for the renamed prepare_cp_linear_attention_metadata. Co-Authored-By: internal-model * docs(ezpz): 60/40 corpus kind-shift + MMLU letter-prior gating notes Subagent fanout: FineWeb-Edu 60/40 kind-shift proposal (SmolLM2 33.6% @38B vs current 94.8% DCLM monoculture) + MMLU letter-prior gating appendix (constant-D 0.2689 > all 2B 0.2413-0.2655 is harness prior). 5 files (2 new + 3 updated indexes), no compute. Co-Authored-By: internal-model * fix(ezpz): CPT-FWE 4N to PPN=8 + 60/40 kind-shift config 12483035 failed: world_size 60 (5xPPN12) 11008%60!=0 FSDP uneven sharding plus missing MDS_ANNEAL_BASE on Sunspot (~/torchtitan has no outputs/, lives on TEGU at .../projects/saforem2/.../step-0). Fix: select=4 PPN=8 -> 32r (11008%32==0), export MDS_ANNEAL_BASE to TEGU path. Adds agpt_2b_mds_mix_owm_edu_6040 (SmolLM2 60/40 FWE/DCLM stage-1). Co-Authored-By: internal-model * fix(ezpz): port _agpt_2b_mds_mix_blend to Grain DatasetMix + 60/40 HFDataSource/InterleavedHuggingFaceTextDataLoader deleted in pytorch#4088; previous mix builders always crashed. Port to GrainDataLoader (DatasetMix after ConcatThenSplitPacking) so weights count packed 8192-token rows (token-weighted). Adds agpt_2b_mds_mix_owm_edu_6040 (SmolLM2 60/40). CPT script already switched to PPN=8 and MDS_ANNEAL_BASE TEGU path (prior 12483035 failed on both). Co-Authored-By: internal-model * fix(ezpz): re-add agpt_debugmodel_gsm8k_plus_distill_streaming (clobbered by CPT push) * docs(ezpz): 2088N umbrella post-mortem + per-seat resubmit Placeholder 9053470 (select=2088, 24h) ran 4h26m — a single GPU fatal error (grf_fatal_singlesubslice_error on x4415c5s5b0n0, 10B slice) made PBS kill the whole 2088N job and all four seats. 20B-512 hung after 10854 (watchdog restart, no new ckpt), 20B-256 saved step-21100, 4B saved step-2600, 10B at 768N never trained (step-1 loss 17788+). Resubmitted as one PBS job per seat (seat-autoretry-20261111.pbs + submit-seats-20261111.sh): 10B moved 768N->512N, HF cache on /tmp. Umbrella PBS retained for provenance. Journal + PROD/README updated. Co-Authored-By: internal-model * style(ezpz): lint grain-sft-cot ufmt on config_registry and cp_linear_attention, license header on build_olmo_mix_manifest, spell out FW-Edu and 'reused' for codespell. * docs(ezpz): fix broken journal links in production README * fix(ezpz): shuffle olmo-mix manifests so the v2 mix is not a curriculum split_dataset_by_node gives rank r files r, r+dp, ..., so a sorted manifest feeds the subsets in path order. The builder now writes a seed-0 shuffle by default. The 10B seat defaults to olmo-mix-dp6144-shuf0.txt; the 4B stays on the sorted file it resumes from. * fix(models): CP KDA/GDN check their attn_gym exports at build Port upstream's require_attn_gym calls for ContextParallelInnerKDA and ContextParallelInnerGDN. Without them the four context-parallel cases in test_optional_imports.py (copied from upstream on this branch) built successfully with a missing backend and failed. * SFT script: CKPT_DIR respect -v override so CPT-17000 lane writes agpt2b-cpt17000-gsm8k-3ep not default ep3 (avoids clobbering ckpt93 B2) --------- Co-authored-by: sim <sim@localhost>
Summary
Follow up to #5467 and #5500. attn_gym resolves its backend backed exports on first attribute access (
attn_gym.linear._lazy),causal_conv1d,causal_conv1d_decodeandpaged_causal_conv1dcome fromattn_gym.linear.short_conv, which imports fine, only thegetattrimportsattn_gym.linear.short_conv.cuteand raisesImportError("causal_conv1d requires the optional CuTeDSL backend: ...")chained fromModuleNotFoundError(name="cutlass"). #5467 only deferred aModuleNotFoundErrorraised by the module import itself, sogdn.py/kda.pystill failed to import on a machine without cutlass, and with them everything that importstorchtitan.models.common, 18 of the CPU test modules did not collect on macOS.__getattr__resolves exports through_load_export, anImportErrorwhose cause is a backend'sModuleNotFoundErroris recorded under"<module>.<export>"and the export becomes a placeholder carrying that error, exactly like an export of a module that failed to import. A missing attn_gym module, or anImportErrorthat is not a missing module, still raises at import..ci/docker/requirements.txtpins (noted in the [models] Let the attn_gym facade defer missing-backend import errors #5467 review).getattrsucceeds and nothing is recorded.On a machine without cutlass the models now import,
causal_conv1dis a placeholder, soInnerKDA/InnerGDN(which check it in__init__since #5500) fail at build with the cutlass error instead of at the first forward, andKDAKernel/GDNKernelstill build when their own backends import.Also takes the optional note from the #5500 re review, the build test now breaks one thing per case, so each entry of the
require_attn_gymlists is load bearing.Test plan
tests/unit_tests/cpu/models/common/test_optional_imports.py:test_attention_gym_lazy_exports_with_missing_backend, a fakeattn_gym.linear.short_convresolvescausal_conv1dlazily and fails on cutlass.gdnimports,gdn.causal_conv1dis a placeholder (not_MissingKernelitself), calling it andrequire_attn_gym(causal_conv1d)raiseModuleNotFoundError(name="cutlass"), anImportErrorchained from a missing attn_gym module, and one that is not a missing module, still raise and leave no placeholder. Fails without the facade change (theImportErrorescapes at import), passes with it.test_attention_modules_report_their_own_backend_at_buildis reparametrized over 11 cases, each breaking exactly one thing on a backend of its own, theattn_gym.linear.short_convmodule, or one of the 10 exports therequire_attn_gymlists name (causal_conv1d,chunk_kda,bound_gate,l2norm,chunk_gdn,recurrent_gdn,context_parallel_kda,context_parallel_gdn,context_parallel_conv_history,ContextParallelRouting), broken through the lazy export path. Each case asserts the placeholder is named after what failed and exactly which ofKDAKernel,GDNKernel,InnerKDA,InnerGDN,ContextParallelInnerKDA,ContextParallelInnerGDNfail at build. DroppingContextParallelRoutingfrom thecp_kda.pylist fails only the[ContextParallelRouting]case, without the facade change the 10 export cases fail and the module case passes.On macOS 15 (attn-gym 0.0.17, no cutlass/triton), rebased on a4a62b3,
pytest tests/unit_tests/cpu --collect-onlygoes from 1371 tests collected / 23 errors to 1640 / 5. The 18 errors fixed were all thecausal_conv1dImportError, the 5 that remain areexperiments/graph_trainer/paged_stash_memory_policy.pyimporting triton at module level (3) and an olderrenderersin my env (2), neither touched here. Of the 18 modules, 16 run standalone, 210 passed, 2 fail for platform reasons (qwen3_8builds a model whose inner modules need cutlass and gets the deferred cutlass error at build,test_lora_forwardruns torch.compile on CPU), the other 2 (kimi_k3/test_kimi_k3_config.py,recipes/test_debug_config_defaults.py) hit the graph_trainer triton import when run on their own.test_optional_imports.py25 passed, pre commit on both files passes every hook except pyrefly, which reports the same pre existing diagnostics as main.