• Stefy Lanza (nextime / spora )'s avatar
    fix the recovery path: a 4-bit module's dtype, and the card it kept · 9715d200
    Stefy Lanza (nextime / spora ) authored
    Two bugs that only bite when something else has already gone wrong, so they
    turned a recoverable load into a failed one.
    
    A fully quantized module could not say what dtype it was. transformers has
    
        next(param.dtype for param in self.parameters() if param.is_floating_point())
    
    and a bnb 4-bit module has NO floating-point parameters -- Params4bit are
    uint8 -- so the generator is empty and next() raises StopIteration. diffusers'
    DiffusionPipeline.to() reads module.dtype unguarded while deciding whether to
    warn about fp16-on-cpu, so it escapes enable_model_cpu_offload(); and because
    loads run in a worker thread, Python turns it into
    
        RuntimeError: StopIteration interacts badly with generators and cannot be
        raised into a Future
    
    failing the whole load. Measured on LTX-2.5, whose text encoder is 4-bit: the
    resident attempt did not fit, the fallback to model CPU offload hit this, and
    the load restarted from scratch. The recovery path broke exactly when it was
    needed, and it would do so for any pipeline with an all-4-bit component.
    
    The property asks what dtype a module is, and a quantized module has a good
    answer: the dtype of its storage. The shim falls back to the first parameter
    of any kind, then to float32, and only when the original raises -- a module
    with floating-point parameters is answered exactly as before. Guarded at every
    enable_model_cpu_offload() call site, with a test that fails if one is added
    without a guard.
    
    The injected components kept the GPU between attempts. They are pre-built
    objects held in a local dict and handed to each attempt through _with_quant,
    so freeing the pipeline frees nothing: the dict is still a strong reference
    and whatever the failed attempt moved onto the card stays there.
    
        [video] teardown-leak breaker: 16.9 GB of this pipeline's tensors survived
        teardown; nulled 7581 external reference(s);
        holders: ["2.01 GB dict['weight', 'bias']", ...]
    
    The holders are the modules' own _parameters dicts -- the modules outlived the
    pipeline. The breaker got the VRAM back by stripping them field by field,
    which works, but it guts components the next attempt is about to reuse. They
    are now moved to the CPU at both resident-failure exits: moved, not dropped,
    because the retry needs these same components, which is the whole point of
    injecting them. The breaker stays as the backstop for a component that
    refuses .to('cpu').
    Co-Authored-By: 's avatarClaude Opus 5 <noreply@anthropic.com>
    Claude-Session: https://claude.ai/code/session_014T3rZozi1Ehk96NG1WesgC
    9715d200
Name
Last commit
Last update
codai Loading commit data...
docs Loading commit data...
packaging Loading commit data...
samples Loading commit data...
tests Loading commit data...
third_party Loading commit data...
tools Loading commit data...
.dockerignore Loading commit data...
.gitignore Loading commit data...
AI.PROMPT Loading commit data...
CODERAI_API_DOCUMENTATION.md Loading commit data...
CoderAI.gif Loading commit data...
DISTRIBUTION.md Loading commit data...
LICENSE.md Loading commit data...
MULTIMODAL_CAPABILITIES.md Loading commit data...
MULTIMODAL_UI_EXAMPLES.md Loading commit data...
README.md Loading commit data...
REQUEST-geoclip-embeddings.md Loading commit data...
REQUEST-vpr-embeddings.md Loading commit data...
amdgpu-coredump-05000.bin Loading commit data...
build-oci.sh Loading commit data...
build.ps1 Loading commit data...
build.sh Loading commit data...
coderai Loading commit data...
coderai-broker-implementation-reference.md Loading commit data...
coderai-integration.md Loading commit data...
commands Loading commit data...
osxbuild.sh Loading commit data...
package-oci.sh Loading commit data...
package-tarball.sh Loading commit data...
requirements-acestep.txt Loading commit data...
requirements-crisperwhisper.txt Loading commit data...
requirements-h3.txt Loading commit data...
requirements-latentsync.txt Loading commit data...
requirements-longcat-train.txt Loading commit data...
requirements-longcat.txt Loading commit data...
requirements-melotts.txt Loading commit data...
requirements-musetalk.txt Loading commit data...
requirements-nemo.txt Loading commit data...
requirements-nvidia.txt Loading commit data...
requirements-ocr-paddle.txt Loading commit data...
requirements-ocr.txt Loading commit data...
requirements-pyannote.txt Loading commit data...
requirements-surya.txt Loading commit data...
requirements-vllm.txt Loading commit data...
requirements-vulkan.txt Loading commit data...
requirements.txt Loading commit data...
run-oci.sh Loading commit data...
smoke-test-oci.sh Loading commit data...
todo.md Loading commit data...