Repository navigation
Conversation
…fer (ModelCloud#4876) `detach_cpu_operand` was added for ModelCloud#4785 so a CPU int4 repack does not keep a `safetensors` mapping pinned through `g_idx`/`scales` views, but it cloned unconditionally. That duplicated buffers the module already owns and broke the ModelCloud#4395 item-1 identity contract: the int4pack snapshot must not rebind `scales`, because the byte-identical second copy was the thing ModelCloud#4395 removed. A `safetensors` (or `torch.frombuffer`) storage is file-backed and therefore not resizable; an ordinary allocation is. Copy only when the storage is not resizable, and return everything else unchanged. Non-CPU tensors, `None` and non-tensors keep their previous behaviour. Regression tests (red on the parent commit): `tests/test_detach_cpu_operand_4876.py` pins the discriminator on both sides — a module-owned tensor and a view of one keep their identity, while an `mmap` and a non-owning `bytearray` buffer are copied. The two `test_int4pack_snapshot_drops_duplicate_operands` cases from ModelCloud#4395 that this broke are green again.
Collaborator
Author
|
Superseded by #4878, which landed the same discriminator on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
detach_cpu_operand(gptqmodel/nn_modules/qlinear/__init__.py), added by #4842/#4849 for #4785, cloned unconditionally. That regressed two #4395 assertions: the int4pack transform must not rebind or clone the checkpointscalesbuffer, because removing that byte-identical second copy is the whole point of #4395 item 1. Closes #4876.The helper now copies only a tensor that really aliases the checkpoint:
resizable()safetensors/mmap/torch.frombufferover a bufferFalseTrueNone, non-tensorA backend without
resizable()keeps the previous fail-safe behaviour (clone), so no platform loses the #4785 protection.Tests
New file
tests/test_detach_cpu_operand_4876.pypins both sides of the discriminator — the #4785 test only covered the mmap side and the #4395 test only covered the module side, so nothing pinned the choice:The two failures named in the issue are green again:
ruff checkon the helper and the new test: All checks passed.Logic Flow Documentation
Not applicable: one predicate added to an existing helper.
Model Support / Module Plan
Not applicable: no definition, plan, or checkpoint-layout change.