Skip to content

feat: resumable model-free PTQ with meta-tensor skip - #2993

Open
kylesayrs wants to merge 1 commit into
mainfrom
nvfp4-meta-tensor-pathway
Open

feat: resumable model-free PTQ with meta-tensor skip#2993
kylesayrs wants to merge 1 commit into
mainfrom
nvfp4-meta-tensor-pathway

Conversation

@kylesayrs

Copy link
Copy Markdown
Collaborator

Summary

  • Adds resume/skip pathway to process_file(): when the output shard already exists, loads tensor metadata via safe_open on meta device instead of re-computing quantization
  • Adds os.makedirs in process_file_microscale_scheme() to ensure output directory exists before saving
  • Hardcodes format to float-quantized in save_utils for correct config generation

Companion PR: compressed-tensors#810 adds _skip_meta_device decorator to NVFP4PackedCompressor.compress() for meta-device tensor handling

Test plan

  • Run model-free PTQ end-to-end, interrupt mid-run, resume — verify it picks up from last saved shard
  • Verify microscale scheme output directory creation works for nested paths
  • Verify quantization_config in output config.json has correct format field

🤖 Generated with Claude Code

Add resume/skip pathway to process_file(): when the output shard already
exists, load its tensor metadata via safe_open on meta device instead of
re-computing quantization. This enables interrupted runs to resume from
where they left off.

Also adds os.makedirs in process_file_microscale_scheme() to ensure the
output directory exists before saving, and hardcodes format to
float-quantized in save_utils for correct config generation.

Companion: vllm-project/compressed-tensors#810

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 83257e2d-d592-41ee-b551-b69dc29a658e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to llm-compressor. Please add the ready label when the PR is ready for review.

Note: This is required to complete the testing suite, please only add the label once the PR is code complete and local testing has been performed.

@mergify

mergify Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

The quality checks have failed. Please run make style and make quality under
the root directory to adddress the lint failures. You will need to install the
dev optional install to get the required linting packages:
https://github.com/vllm-project/llm-compressor/blob/main/CONTRIBUTING.md

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces optimization and safety improvements to the model-free entrypoint, including skipping processing if the output file already exists and ensuring the output directory is created before saving. Feedback on these changes highlights a critical issue where using safe_open with device="meta" and calling get_tensor will cause a runtime error, suggesting instead to parse the safetensors header directly. Additionally, hardcoding the quantization format to "float-quantized" is flagged as a breaking change for other formats, with a recommendation to use a fallback mechanism instead.

Comment on lines +130 to +133
with safe_open(save_path, framework="pt", device="meta") as f:
for key in f.keys():
tensor_meta = f.get_tensor(key)
tensors[key] = tensor_meta

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

Using safe_open with device="meta" and calling f.get_tensor(key) will raise a RuntimeError at runtime (e.g., RuntimeError: Cannot copy to/from a Meta tensor) because meta device tensors do not have storage and cannot have data copied into them. To load the tensors as meta tensors without loading their data into memory, we can parse the safetensors file header directly using standard file I/O and construct the meta tensors using str_to_torch_dtype.

        import json
        import struct
        tensors = {}
        with open(save_path, "rb") as f:
            header_size_bytes = f.read(8)
            if len(header_size_bytes) == 8:
                header_size = struct.unpack("<Q", header_size_bytes)[0]
                header_bytes = f.read(header_size)
                header = json.loads(header_bytes.decode("utf-8"))
                for key, metadata in header.items():
                    if key != "__metadata__":
                        shape = metadata["shape"]
                        dtype = str_to_torch_dtype(metadata["data_type"])
                        tensors[key] = torch.empty(shape, dtype=dtype, device="meta")

"ignore": ignore,
"quantization_status": QuantizationStatus.COMPRESSED,
"format": scheme.format,
"format": "float-quantized",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Hardcoding the format to "float-quantized" will break configuration generation for other quantization formats, such as integer quantization (e.g., "int-quantized"). If the goal is to provide a fallback or handle cases where scheme.format is not set, we should use a fallback instead of unconditionally overriding it.

Suggested change
"format": "float-quantized",
"format": scheme.format or "float-quantized",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this?

@mergify

mergify Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🔴 1 of 1 protections blocking · waiting on 👀 reviews

Protection Waiting on
🔴 Require one maintainer review 👀 reviews

🔴 Require one maintainer review

Waiting for any of

  • approved-reviews-by=HDCharles
  • approved-reviews-by=brian-dellabetta
  • approved-reviews-by=dsikka
  • approved-reviews-by=kylesayrs
  • approved-reviews-by=yiliu30
This rule is failing.

All PRs must have at least one approving review from a maintainer before merging.

  • any of:
    • approved-reviews-by=HDCharles
    • approved-reviews-by=brian-dellabetta
    • approved-reviews-by=dsikka
    • approved-reviews-by=kylesayrs
    • approved-reviews-by=yiliu30
  • #changes-requested-reviews-by = 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants