Skip to content

fix(writer): accept safe nested per-layer shard paths in EXL3 passthrough - #3846

Merged
Qubitium merged 2 commits into
mainfrom
fix/3828-exl3-nested-shard
Nov 13, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/3828-exl3-nested-shard

Conversation

@ZX-ModelCloud

@ZX-ModelCloud ZX-ModelCloud commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

The EXL3 native checkpoint passthrough builder rejected every safetensors index shard entry whose name was not a bare basename. The public reshard() per-layer layout writes nested paths such as model.layers.0/layer.safetensors, so a valid resharded source could not be published and save_quantized() aborted with:

RuntimeError: Checkpoint shard name is unsafe: model.layers.0/layer.safetensors

Root cause

_build_exllamav3_checkpoint_passthrough_state_dict() validated shard names with:

if os.path.basename(shard_name) != shard_name or shard_name in {".", ".."}:
    raise RuntimeError(...)

The guard was introduced in #3602 and is unchanged by #3712. reshard() has always emitted model.layers.0/layer.safetensors (see its docstring and tests/test_reshard.py), so the guard rejects a supported layout.

Fix

Add _is_safe_relative_checkpoint_shard() and use it in place of the basename check. It accepts nested relative paths but still rejects:

  • absolute paths and drive-qualified paths
  • backslashes and NUL bytes
  • empty, . and .. components

The existing Hugging Face snapshot behavior is preserved: basename symlinks that resolve outside the snapshot root (to the shared blobs/ directory) remain allowed, because the guard validates the index entry, not the resolved path.

Tests

  • tests/test_writer_state_overlay.py::test_exl3_checkpoint_passthrough_accepts_reshard_per_layer_shards builds the real reshard() per-layer layout and verifies the passthrough preserves the native norm and embedding while replacing only the projection.
  • tests/test_writer_state_overlay.py::test_exl3_checkpoint_passthrough_rejects_unsafe_shard_paths covers absolute, traversal, ./, //, and backslash entries.

Validation

  • pytest tests/test_reshard.py tests/test_writer_state_overlay.py — 57 passed
  • pytest tests/test_writer_attention.py tests/test_writer_dynamic_order.py tests/test_writer_instance_attrs.py tests/test_writer_quant_log.py — 21 passed
  • ruff check gptqmodel docs/eora tests setup.py passes

Notes

This is a localized validation fix; no control-flow or lifecycle change, so no logic-flow diagrams are needed. The LazyTurtle active-staging branch still requires a bare basename, but that path is not part of this report (the reproduction uses staging unset) and is left unchanged.

The second commit only reorders the from .quantizer import (...) names in gptqmodel/quantization/gptq.py, which #3845 left unsorted and which makes the repository lint gate fail on main independently of this change.

Fixes #3828.

…ough

The EXL3 native checkpoint passthrough builder rejected every index shard
entry whose name was not a bare basename. The public reshard() per-layer
layout emits nested paths such as model.layers.0/layer.safetensors, so a
valid resharded source could not be published.

Accept safe relative paths while still rejecting absolute or
drive-qualified paths, backslashes, NUL bytes, and empty, "." or ".."
components. Hugging Face snapshot symlinks that resolve outside the source
root remain permitted.

Adds regression coverage for the reshard() layout and for rejected unsafe
paths.
@ZX-ModelCloud
ZX-ModelCloud force-pushed the fix/3828-exl3-nested-shard branch from 41980fc to e3067bf Compare November 13, 2026 09:13
Restore the import order required by ruff after #3845 so the repository
lint gate passes again.
@Qubitium
Qubitium merged commit 7af3d7b into main Nov 13, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/3828-exl3-nested-shard branch November 13, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] EXL3 native export rejects safe per-layer shard paths emitted by reshard

2 participants