comfy.utils.load_safetensors() (used by VAELoader and other loaders when
the DynamicVRAM/aimdo backend is active) never validated that the
memory-mapped file actually contained as many bytes as the safetensors
header declared. When a .safetensors file was truncated -- e.g. still
downloading, or an interrupted/partial download -- Python's silent slice
clipping handed torch.frombuffer() a short buffer, producing the
inscrutable low-level error:
ValueError: buffer length (N bytes) after offset (0 bytes) must be
a multiple of element size (4)
instead of the clear "corrupt/incomplete file" message already produced
by the sibling (non-aimdo) safetensors.safe_open() code path for the same
underlying condition.
This adds an explicit bounds check against the header's declared data
size and raises the same friendly, actionable ValueError used elsewhere
in load_torch_file() for corrupt/incomplete files.
Fixes#14784 (reported by xnx20050723-lgtm).
Since comfy_aimdo's ModelMMAP requires a compiled, GPU-platform-specific
native backend unavailable in CI/dev environments without a real GPU, the
added test monkeypatches ModelMMAP with a fake backed by a real,
synthetic, truncated safetensors buffer, letting
comfy.utils.load_safetensors() itself be exercised deterministically.
Verified revert-proof: reverting the fix reproduces the exact reported
error string, `buffer length (37 bytes) after offset (0 bytes) must be a
multiple of element size (4)`.
When a prompt is submitted without client_id and its output nodes are
served from cache, _send_cached_ui returned early before recording the
cached UI outputs, so /api/jobs/{job_id} (and /history) reported success
with empty outputs. Record the outputs before the client_id check.
#14862 auto-enables the comfy-kitchen Triton backend whenever torch.version.hip
is set and Triton >= 3.7. The INT8 matmul kernels compile tl.dot to matrix-core
instructions (WMMA on RDNA3+/gfx11xx-gfx12xx, MFMA on CDNA/gfx9xx); RDNA1/RDNA2
(gfx10xx) have neither, so the auto-enabled INT8 path hangs the GPU there
(reported on RDNA2 + triton-windows 3.7.1: native and custom-node INT8 freeze
until reset).
Gate the automatic ROCm default on GPU architecture as well as Triton version so
RDNA1/RDNA2 stay on the working eager fallback. Add --disable-triton-backend as
an explicit override; --enable-triton-backend still force-enables on any arch.
On AMD/ROCm the CUDA backend is unavailable, so Triton is the only accelerated
comfy-kitchen backend. It was disabled by default (opt-in --enable-triton-backend),
leaving AMD on the slow eager path. Enable it by default when torch.version.hip is
set AND Triton is >= 3.7 -- older Triton lacks libdevice.rint on the HIP backend and
hard-crashes the INT8 path, so on Triton < 3.7 it stays disabled with a log line.
NVIDIA behavior is unchanged; the explicit --enable-triton-backend flag still works
as an override.
Fixes#14861