12 KiB
Qwen recurrent backend admission
Issue #384 remains open. There is no qualified FLA/causal-conv1d phase bound. The estimator continues to report unknown demand for these compiled paths; default mode warns and strict mode refuses. No backend is loaded, downloaded, compiled, or executed by admission.
The implemented correction checks all four frozen Qwen callsites: chunk scan,
single-token recurrent scan, convolution forward, and convolution update. It
also checks every model submodule for Hub kernel selection before accepting the
torch fallback. An installed package version or a function name copied with
functools.wraps cannot qualify a replacement. This inspection is an allocation
contract check, not authentication of arbitrary modified Python installations.
The existing torch workspace formulas and Mamba backend handling are unchanged.
flowchart LR
Q[Four frozen Qwen scan/convolution callsites] -->|inspect without execution| I[Callable and Hub-selection checks]
H[Hub-kernel flags on every submodule] -->|inspect without loading kernels| I
I -->|recognized torch fallbacks| T[Existing finite geometry estimates]
I -->|unqualified or opaque selection| U[Unknown demand]
U -->|default mode| W[Warn before work]
U -->|strict mode| R[Refuse before work]
Finite torch estimates are not compiled-backend or hardware qualification;
fail-closed still requires calibrated components.
Source and environment examined
The CPU environment has torch 2.13.0+cpu and Transformers 5.15.0.
Neither it nor the local CUDA environment contains FLA or causal-conv1d source.
The CUDA environment has Triton 3.7.1; its source was read without invoking
CUDA. No environment or dependency manifest was changed, and no GPU run was
performed for this change.
Primary sources inspected at exact upstream tags:
- Transformers 5.15.0 Qwen3.5 callsites and kernel selection.
- FLA 0.5.2 chunk forward, intra-chunk allocations, WY buffers, chunk states, output, gate cumsum, L2 normalization, and fused recurrent forward.
- causal-conv1d 1.7.0 Python interface, custom-op allocation wrappers, and C++ checks/dispatch.
Transformers resolves optional implementations once into an implementation
closure. The advertised __wrapped__ remains the torch fallback. Prefill uses
the chunk scan; a previous recurrent state plus one input token selects the
recurrent scan. Convolution has a separate forward/update selection. The four
choices are independent: an installed FLA package does not establish all four.
In particular, Transformers 5.15.0 requests recurrent_gated_delta_rule, while
FLA 0.5.2 exports
fused_recurrent_gated_delta_rule. The inspected resolver falls back to torch
when the requested export is absent. A future estimator must inspect the actual
frozen targets and support or reject this mixed path explicitly. The issue's
A100 report does not specify its Transformers version, so this local callsite
analysis does not identify that run's exact path.
Allocation inventory, not an admission bound
For the default equal-length FLA chunk path, let B,T,H,K,V be batch, tokens,
effective heads after Qwen's head repetition, key width and value width; s is
the Q/K/V element width. Use chunk size 64, no context parallelism, no packed
sequences, no fused gate/beta activation, and inference without autograd.
These are individual allocations, not a complete peak formula:
| Allocation | Logical bytes |
|---|---|
| Normalized Q and K plus their FP32 inverse norms | 2*B*T*H*K*s + 2*B*T*H*4 |
| Gate cumulative sum | B*T*H*4 |
| Solved intra-chunk matrix A | B*T*H*64*s |
| WY W and U | B*T*H*(K+V)*s |
| Chunk boundary states | B*ceil(T/64)*H*K*V*s |
| Updated values and scan output | 2*B*T*H*V*s |
| Optional final state | B*H*K*V*4 |
| Fused recurrent forward output and optional final state | B*T*H*V*s + B*H*K*V*4 |
The input guard can additionally make contiguous copies. Qwen projections, head repetition, normalization, cache storage and cache-update concatenations live outside this inventory. Tensor lifetimes and aliases must be counted at their actual overlap. Packed sequences, other chunk sizes, autograd and alternative dispatch paths have different allocations and are not covered by this inventory.
For causal-conv1d, the custom-op forward and update wrappers allocate an output with the input's shape/dtype. The Python forward wrapper may additionally copy noncontiguous operands and allocate requested final states. C++ accepts kernel widths 2–4 and FP32/FP16/BF16, and imposes alignment requirements for channel-last forward. The effective convolution input length comes from the Transformers cache callsite, not necessarily the new token count. These facts alone do not qualify an arbitrary loaded extension or the complete surrounding model phase.
Missing proof
- FLA runtime dispatch lazily initializes registries and selects implementations at the public entry point and inside normalization, chunk, and common helpers. Checking only the public function's module/name/version misses nested replacements. Admission must not initialize those registries to discover a bound.
- FLA autotuning can fall through to Triton, load configurable kernel settings, and clone restore-value operands. A warm tensor trace does not cover the first call.
- Triton 3.7.1 NVIDIA runtime allocates launch scratch from compiled metadata. Its default benchmark also allocates a 256 MiB cache-flush buffer. No proof of the relevant compiled scratch sizes, custom hooks/allocator behavior, or all cold-path allocations was established here. Adding 256 MiB alone would not resolve these gaps.
Consequently neither the source inventory nor the reported 55,974 MiB A100 peak is sufficient to enable compiled admission. Supporting a finite subset requires binding all selected callables, package/compiler versions, dispatch state, geometry, dtype, layout and runtime allocation behavior. Unknown cases must keep strict refusal. Training/backward requires a separate contract.
CPU regression checks
tests/test_phase_admission_recurrent_backends.py checks all four callsites
across Qwen3-Next/Qwen3.5/Qwen3.5-MoE, opaque known/unknown version claims,
wrapped replacements, later-layer Hub selection, and import-free inspection.
Real tiny Qwen3.5 FP32/BF16 forwards cover 1/64/65/129-token prefill and cached
single-token decode. Exact existing torch chunk/decode arithmetic is preserved.
These tests do not qualify CUDA kernels.
Serial RTX 4090 qualification procedure
The conductor needs an independently prepared CUDA environment with the exact FLA 0.5.2 and causal-conv1d 1.7.0 packages. Run the following from the worktree, with no concurrent GPU workload. It creates random local weights and makes no model downloads. This is a pending acceptance test: it explicitly requests strict modelling and rejects any returned unknown component before the measured forward. With the current unsupported compiled backends, strict modelling raises before that forward. Do not remove these checks or substitute the torch geometry estimate to obtain a passing measurement. Once a source-qualified bound is implemented, this compares it against PyTorch allocator peaks for first and repeated forwards in the process. It does not guarantee empty compiler/autotune caches or measure allocations outside the PyTorch allocator:
HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 PYTHONPATH=. python - <<'PY'
import inspect
from importlib.metadata import version
import torch
from transformers import Qwen3_5ForCausalLM, Qwen3_5TextConfig
from transformers.models.qwen3_5 import modeling_qwen3_5 as owner
from obliteratus import phase_admission as a
from obliteratus.models.loader import ModelHandle
assert torch.cuda.is_available(), "CUDA evidence unavailable"
for package, expected in (("flash-linear-attention", "0.5.2"),
("causal-conv1d", "1.7.0")):
assert version(package) == expected, (package, version(package))
print(torch.cuda.get_device_name(0), torch.__version__, version("transformers"), version("triton"))
for name in ("torch_chunk_gated_delta_rule", "torch_recurrent_gated_delta_rule",
"causal_conv1d_fn", "causal_conv1d_update"):
selected = getattr(owner, name)
target = inspect.getclosurevars(selected).nonlocals.get("implementation", selected)
print(name, target.__module__, target.__name__)
if name != "torch_recurrent_gated_delta_rule":
expected = "fla." if "delta_rule" in name else "causal_conv1d."
assert target.__module__.startswith(expected), "compiled path was not selected"
torch.manual_seed(7)
config = Qwen3_5TextConfig(
vocab_size=256, hidden_size=128, intermediate_size=256, num_hidden_layers=2,
num_attention_heads=4, num_key_value_heads=2, head_dim=32,
layer_types=["linear_attention", "full_attention"],
linear_num_key_heads=2, linear_num_value_heads=4,
linear_key_head_dim=128, linear_value_head_dim=128, linear_conv_kernel_dim=4,
)
model = Qwen3_5ForCausalLM(config).eval().to("cuda", dtype=torch.bfloat16)
handle = ModelHandle(model, None, config, "local-random-qwen3.5", "causal_lm")
def measure(inputs, cache, total):
demand = a.model_phase_demand(handle, "probe", mode="strict", forward_workloads=[
a.ForwardWorkload(inputs.shape[0], inputs.shape[1], cache_tokens=total,
attention_mask=False),
])
assert all(component.bytes is not None for component in demand.components), (
"unknown phase demand; refusing measured forward"
)
bound = demand.devices["cuda:0"].additional_bytes
torch.cuda.synchronize()
torch.cuda.empty_cache()
torch.cuda.reset_peak_memory_stats()
before = torch.cuda.memory_allocated()
with torch.inference_mode():
result = model(inputs, past_key_values=cache, use_cache=True)
torch.cuda.synchronize()
peak = torch.cuda.max_memory_allocated() - before
print(tuple(inputs.shape), total, "bound", bound, "peak", peak)
assert torch.isfinite(result.logits).all()
assert 0 < peak <= bound, (peak, bound)
return result.past_key_values
for batch in (1, 2):
for tokens in (1, 63, 64, 65, 129):
inputs = torch.ones(batch, tokens, device="cuda", dtype=torch.long)
for repetition in range(2):
cache = measure(inputs, None, tokens)
for step in (1, 2):
cache = measure(inputs[:, :1], cache, tokens + step)
del cache
PY
A passing small-model RTX 4090 test would cover only those shapes, callables, dtype and device. Full Qwen 27B BF16 qualification on an A100 80 GB remains required for the reported workload, including its actual prompt/cache limits, linear/full-attention schedule, edits, reloads and phase receipts. No such hardware evidence is claimed by this change.