Alexander Claude Opus 5 (1M context) commited on
Commit
9fd7ff2
·
1 Parent(s): 922bc19

Record the open text-encoder task: bitsandbytes 4-bit is unusable on ZeroGPU

Browse files

Both hypotheses behind the previous fix are disproved by the VRAM telemetry:
the failure is identical inside the GPU call where CUDA is real, and 21.7 GB of
50.9 GB is free when a 118 MB allocation fails. bitsandbytes' 4-bit CUDA backend
is simply broken on this ZeroGPU/PyTorch/Blackwell combination -- it never
reaches its fused kernel, landing in _dequant_linear_fallback.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VNp8YiVRcjWBNqPguTw85h

Files changed (1) hide show
  1. TASKS.md +78 -0
TASKS.md ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Open task: replace the 4-bit text encoder (bitsandbytes does not work here)
2
+
3
+ Status as of 2026-08-21, commit `922bc19`. Everything except prompt encoding is
4
+ verified working; this is the one thing standing between the Space and a
5
+ completed run.
6
+
7
+ ## What happens
8
+
9
+ Every generation dies at the first Gemma forward:
10
+
11
+ ```
12
+ [vram] call start allocated=28.7 GB reserved=28.7 GB free=21.7/50.9 GB
13
+ [vram] before prompt encode allocated=28.7 GB reserved=28.7 GB free=21.7/50.9 GB
14
+ ...
15
+ bitsandbytes/backends/cuda/ops.py:914 _dequant_linear_fallback
16
+ torch.empty(shapeB, dtype=A.dtype, device=A.device)
17
+ RuntimeError: NVML_SUCCESS == r INTERNAL ASSERT FAILED at
18
+ "/pytorch/c10/cuda/CUDACachingAllocator.cpp":1165
19
+ ```
20
+
21
+ ## What the numbers rule out
22
+
23
+ The first fix moved the Gemma build from module scope into the `@spaces.GPU`
24
+ call, on the theory that bitsandbytes quantizes during the move to CUDA and was
25
+ therefore doing it against ZeroGPU's *emulated* CUDA. **That was wrong** — the
26
+ failure is identical inside the call, where CUDA is real.
27
+
28
+ The "masked OOM" reading is also wrong. The slice is 50.9 GB with 28.7 GB
29
+ resident, so **21.7 GB is free** at the moment of failure, and the allocation
30
+ that fails is a dequantized `[15360, 3840]` bf16 weight — about 118 MB.
31
+
32
+ What is left is the plain reading: **bitsandbytes' 4-bit CUDA backend is broken
33
+ on this ZeroGPU / PyTorch / Blackwell combination.** Note it never reaches its
34
+ fused kernel at all — `_dequant_linear_fallback` is the "no usable kernel" path,
35
+ which is consistent with the installed bitsandbytes lacking sm_120 support.
36
+
37
+ Independently: bnb's fused `gemm_4bit` only covers single-token decode anyway, so
38
+ even a working bnb would have taken the dequantize-then-matmul path for a
39
+ 1024-token prompt. 4-bit was never going to be fast here.
40
+
41
+ ## Why the obvious fallback does not fit
42
+
43
+ `FOLEY_TEXT_ENCODER_4BIT=0` loads bf16 Gemma — but that is 24.4 GB against
44
+ 22.2 GB free, so it OOMs for real. It also needs `HF_TOKEN` (gated repo). The
45
+ resident transformer and a bf16 text encoder cannot share a 50.9 GB slice.
46
+
47
+ ## The fix to build
48
+
49
+ Quantize Gemma with **plain PyTorch, no third-party kernels** — the same trick
50
+ `ltx_core.quantization.fp8_cast` uses on the transformer: store `weight` as
51
+ `float8_e4m3fn` plus a per-tensor scale, upcast in `forward`, then `F.linear`.
52
+ Roughly 30 lines, swapped over the encoder that LTX's own builder returns.
53
+
54
+ - Footprint ~12 GB → 28.7 + 12 = 40.7 GB, ~10 GB of headroom. Fits.
55
+ - One forward per *new* prompt only, thanks to the disk prompt cache, and it is
56
+ memory-bound rather than compute-bound, so an unfused upcast is fine.
57
+ - Cost: the source weights are the gated 24.4 GB bf16 repo, so the Space needs
58
+ `HF_TOKEN` and the disk for it. ZeroGPU deletes blobs after packing, and this
59
+ encoder is not packed, so check the download survives startup.
60
+
61
+ Alternatives worth a look first, both avoiding bitsandbytes and the gated repo:
62
+
63
+ - `leon-se/gemma-3-12b-it-FP8-Dynamic` (~12 GB, compressed-tensors)
64
+ - `abhishekchohan/gemma-3-12b-it-quantized-W4A16` (8.4 GB, compressed-tensors)
65
+
66
+ Both are vanilla rather than QAT weights, so prompt adherence may shift slightly
67
+ from what LTX was trained against; worth one A/B once anything runs end to end.
68
+
69
+ ## Verified and not in scope
70
+
71
+ - Residency works: `ZeroGPU tensors packing: 28.7G`, and `[vram] call start`
72
+ confirms all 28.7 GB is live in the worker.
73
+ - The Foley LoRA fuses into the fp8 checkpoint at module scope.
74
+ `fp8_scaled_mm_fuse_rule` is pure PyTorch, so `tools/build_foley_checkpoint.py`
75
+ is an optimization, not a prerequisite.
76
+ - Video normalization and chunk planning ran correctly:
77
+ `512x288, 281 frames (11.71s), 4 chunk(s)`.
78
+ - ZeroGPU frees the source blobs after packing, so disk is not a concern.