Repository navigation
[models] Report the missing backend per Attention Gym kernel - #5500
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 25s —— View job Review: per-kernel backend errors for the attn_gym facadeThe change is correct and fixes the problem it targets: when one attn_gym module fails on a backend, that failure no longer blocks kernels from other modules. Turning placeholders into per-module subclasses, cached in 1. The narrower build check lets CP backend failures through until
|
|
@mkhilari could you address comments |
Thanks @tianyu-l for the review. Pushed a follow up commit addressing it:
Verified on macOS without cutlass/triton, |
|
@claude review again |
|
Claude finished @tianyu-l's task in 1m 38s —— View job Re-review after f51e271I have no blocking comments. All five points from the first review are addressed, and the new commit reads cleanly.
Earlier points
Checks on the lists against actual call sites
Remaining nits (optional)
Not verifiedI couldn't run |
…#5565) ## 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_decode` and `paged_causal_conv1d` come from `attn_gym.linear.short_conv`, which imports fine, only the `getattr` imports `attn_gym.linear.short_conv.cute` and raises `ImportError("causal_conv1d requires the optional CuTeDSL backend: ...")` chained from `ModuleNotFoundError(name="cutlass")`. #5467 only deferred a `ModuleNotFoundError` raised by the module import itself, so `gdn.py` / `kda.py` still failed to import on a machine without cutlass, and with them everything that imports `torchtitan.models.common`, 18 of the CPU test modules did not collect on macOS. - `__getattr__` resolves exports through `_load_export`, an `ImportError` whose cause is a backend's `ModuleNotFoundError` is 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 an `ImportError` that is not a missing module, still raises at import. - The install hint now names attn gym 0.0.17, the version `.ci/docker/requirements.txt` pins (noted in the #5467 review). - No change when every backend imports, `getattr` succeeds and nothing is recorded. On a machine without cutlass the models now import, `causal_conv1d` is a placeholder, so `InnerKDA` / `InnerGDN` (which check it in `__init__` since #5500) fail at build with the cutlass error instead of at the first forward, and `KDAKernel` / `GDNKernel` still 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_gym` lists is load bearing. ## Test plan `tests/unit_tests/cpu/models/common/test_optional_imports.py`: - New `test_attention_gym_lazy_exports_with_missing_backend`, a fake `attn_gym.linear.short_conv` resolves `causal_conv1d` lazily and fails on cutlass. `gdn` imports, `gdn.causal_conv1d` is a placeholder (not `_MissingKernel` itself), calling it and `require_attn_gym(causal_conv1d)` raise `ModuleNotFoundError(name="cutlass")`, an `ImportError` chained 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 (the `ImportError` escapes at import), passes with it. - `test_attention_modules_report_their_own_backend_at_build` is reparametrized over 11 cases, each breaking exactly one thing on a backend of its own, the `attn_gym.linear.short_conv` module, or one of the 10 exports the `require_attn_gym` lists 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 of `KDAKernel`, `GDNKernel`, `InnerKDA`, `InnerGDN`, `ContextParallelInnerKDA`, `ContextParallelInnerGDN` fail at build. Dropping `ContextParallelRouting` from the `cp_kda.py` list fails only the `[ContextParallelRouting]` case, without the facade change the 10 export cases fail and the module case passes. - The two install hint asserts updated to 0.0.17. On macOS 15 (attn-gym 0.0.17, no cutlass/triton), rebased on a4a62b3, `pytest tests/unit_tests/cpu --collect-only` goes from 1371 tests collected / 23 errors to 1640 / 5. The 18 errors fixed were all the `causal_conv1d` `ImportError`, the 5 that remain are `experiments/graph_trainer/paged_stash_memory_policy.py` importing triton at module level (3) and an older `renderers` in my env (2), neither touched here. Of the 18 modules, 16 run standalone, 210 passed, 2 fail for platform reasons (`qwen3_8` builds a model whose inner modules need cutlass and gets the deferred cutlass error at build, `test_lora_forward` runs 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.py` 25 passed, pre commit on both files passes every hook except pyrefly, which reports the same pre existing diagnostics as main.
Summary
Follow up to #5467 (review point 2 there). The facade recorded backend import errors per attn_gym module, but every placeholder raised the first recorded error, so with, say,
attn_gym.sparsefailing on cutlass and the GDN modules importing fine,GDNKernel.Config().build()reported cutlass although GDN would have worked._MissingKernelsubclass carrying that module's error (one subclass per module, cached, named_MissingKernel[<attn_gym module>]). Calling it,.apply, or.from_fragmentsraises a freshModuleNotFoundErrorwith that backend's name and message.is_missing_kernel()(aTypeGuard) replaces theis not _MissingKernelidentity checks inkda.py,gdn.py,linear_attention.pyandcp_linear_attention.py, so the subclasses are also kept out of SPMD registration.require_attn_gym(kernel, *kernels)checks the given exports and each module calls it from__init__with every export it uses, so a build error names the backend that module needs:KDAKernel(chunk_kda,bound_gate,l2norm),GDNKernel(chunk_gdn,recurrent_gdn,l2norm),InnerKDA/InnerGDN(causal_conv1d),ContextParallelInnerKDA/ContextParallelInnerGDN(context_parallel_kda/context_parallel_gdn,context_parallel_conv_history,ContextParallelRouting, andl2normfor GDN). The zero argument form from [models] Let the attn_gym facade defer missing-backend import errors #5467, which raised on any error recorded so far, is gone.attn_gymis missing (the placeholders are the base class and raise the install hint) or when every backend imports.Not in this PR: attn_gym resolves
causal_conv1dand the otherattn_gym.linear.short_convexports lazily (attn_gym.linear._lazy) and raises a plainImportErrorat attribute access, which_load_modulenever sees, so on a machine without cutlassgdn.py/kda.pystill fail to import and 18 CPU test modules do not collect. I have that fixed on top of this branch and will open it next, thecausal_conv1dchecks here are what make it fail at build rather than at the first forward.Test plan
tests/unit_tests/cpu/models/common/test_optional_imports.py:test_attention_modules_report_their_own_backend_at_build: a fake attn_gym whose modules all import except the broken ones. Withattn_gym.linear.short_convfailing on cutlass,KDAKernel/GDNKernelbuild andInnerKDA,InnerGDNand their CP variants fail at build with cutlass, with the three context parallel modules failing on triton, the inner modules build and the CP variants fail with triton. Fails without the__init__checks.…l2norm_fwdfails on triton andattn_gym.linear.kda.impl.fusedon cutlass in one process,_L2Norm()raises triton,_ChunkKDA()/.applyraise cutlass,require_attn_gym(_ChunkKDA)raises cutlass,require_attn_gym(real, _L2Norm)raises triton,require_attn_gym(real, real)passes, the placeholder is named after its module.[cutlass-*]build cases now go throughrequire_attn_gym(kernels)and still seeerror.name == "cutlass".On macOS without cutlass/triton, rebased on e61df55, 15 passed,
tests/unit_tests/cpu/components/checkpointer123 passed (2 known, meta-pytorch/torch_checkpointing#9), pre commit on all files passes every hook except pyrefly, which reports the same pre existing diagnostics as main in files this PR does not touch.