mirror of
https://github.com/NVIDIA/Model-Optimizer.git
synced 2026-11-01 07:53:10 +08:00
## What does this PR do? **Type of change:** refactor / deprecation (examples) Follow-up to #1705 (which consolidated `examples/vlm_ptq` into `examples/llm_ptq`). Since that example now covers Hugging Face **LLM and VLM** PTQ, the `llm_ptq` name is a misnomer. This renames the directory to `examples/hf_ptq` and leaves a relative symlink `examples/llm_ptq → hf_ptq` so existing paths/commands keep working during a deprecation window. Requested by @kevalmorabia97 on #1705 (with the symlink-for-back-compat approach), targeted for the **same 0.46 release** as the consolidation. ### Changes - `git mv examples/llm_ptq → examples/hf_ptq` and `tests/examples/llm_ptq → tests/examples/hf_ptq` (the CI runner maps the matrix name to both `examples/<name>` and `tests/examples/<name>`). - Add a tracked back-compat symlink `examples/llm_ptq → hf_ptq`. - Update CI matrices and all repo **path references** (docs, READMEs, agent skills, launcher/debugger tools, tests) from `llm_ptq` to `hf_ptq`. - Keep Python identifiers / test-util module names (`run_llm_ptq_command`, `llm_ptq_utils`) — they name the LLM-PTQ task, not the directory. - Preserve the CODEOWNERS team slug (`modelopt-examples-llm_ptq-codeowners`) and historical CHANGELOG entries; add a CHANGELOG deprecation note. ### Back-compat caveats (inherent to git directory symlinks) - ✅ Linux/macOS CLI usage and Python `cwd`/pytest resolution work through the symlink. - ⚠️ Windows git checkouts don't materialize symlinks by default (low impact — this example is Linux-only in practice). - ⚠️ GitHub web doesn't follow directory symlinks, so legacy external deep-links to `examples/llm_ptq/...` won't navigate in. All **internal** references are repointed to `hf_ptq`, so the symlink is only for legacy external/CLI use. ### Usage (unchanged via symlink) ```bash # New canonical path cd examples/hf_ptq scripts/huggingface_example.sh --model <hf_model> --quant fp8 # Old path still works (forwards via symlink) cd examples/llm_ptq && scripts/huggingface_example.sh --model <hf_model> --quant fp8 ``` ### Testing - `bash -n` on moved/edited shell scripts (new path + via symlink). - `py_compile` on moved/edited Python; test re-export shim repointed to `examples/hf_ptq/example_utils`. - Verified git tracks `examples/llm_ptq` as a single symlink (mode 120000), not a duplicated tree (no pre-commit / pytest double-processing). - `pre-commit run` on all changed files passes. ### Before your PR is "*Ready for review*" - Is this change backward compatible?: ✅ (relative symlink keeps `examples/llm_ptq` paths valid; see caveats above) - Did you write any new necessary tests?: N/A (pure rename; existing tests moved with the dir) - Did you update Changelog?: ✅ ### Additional Information Follow-up (later release): remove the `examples/llm_ptq` symlink once external references have migrated. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * PTQ guidance now directs to the unified Hugging Face PTQ flow, including VLM quantization via the shared `--vlm` entry point. * **Documentation** * Updated README and guide links, references, and command snippets to use `hf_ptq` (replacing `llm_ptq`). * Deprecated and consolidated `vlm_ptq` into `hf_ptq`; removed VILA/NVILA coverage from the Hugging Face PTQ examples. * **Bug Fixes** * Improved detection and routing so local/manual setup uses the correct PTQ source. * **Tests / Chores** * CI and example tests updated to run the `hf_ptq` variants. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Zhiyu Cheng <zhiyuc@nvidia.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
76 lines
2.5 KiB
Python
76 lines
2.5 KiB
Python
# SPDX-FileCopyrightText: Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
"""Utility functions for running example commands reused in multiple example tests."""
|
|
|
|
import os
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
from _test_utils.torch.distributed.utils import get_free_port
|
|
|
|
MODELOPT_ROOT = Path(__file__).parents[3]
|
|
|
|
|
|
def extend_cmd_parts(cmd_parts: list[str], **kwargs):
|
|
for key, value in kwargs.items():
|
|
if value is not None:
|
|
cmd_parts.extend([f"--{key}", str(value)])
|
|
if kwargs.get("trust_remote_code", False):
|
|
cmd_parts.append("--trust_remote_code")
|
|
return cmd_parts
|
|
|
|
|
|
def run_example_command(
|
|
cmd_parts: list[str],
|
|
example_path: str,
|
|
setup_free_port: bool = False,
|
|
env: dict[str, str] | None = None,
|
|
):
|
|
print(f"[{example_path}] Running command: {cmd_parts}")
|
|
env = env or os.environ.copy()
|
|
|
|
if setup_free_port:
|
|
free_port = get_free_port()
|
|
env["MASTER_PORT"] = str(free_port)
|
|
|
|
subprocess.run(cmd_parts, cwd=MODELOPT_ROOT / "examples" / example_path, env=env, check=True)
|
|
|
|
|
|
def run_command_in_background(
|
|
cmd_parts: list[str], example_path: str, stdout=None, stderr=None, text=True
|
|
):
|
|
print(f"Running command in background: {' '.join(str(part) for part in cmd_parts)}")
|
|
process = subprocess.Popen(
|
|
cmd_parts,
|
|
cwd=MODELOPT_ROOT / "examples" / example_path,
|
|
stdout=stdout,
|
|
stderr=stderr,
|
|
text=text,
|
|
)
|
|
return process
|
|
|
|
|
|
def run_hf_ptq_command(*, model: str, quant: str, vlm: bool = False, **kwargs):
|
|
kwargs.update({"model": model, "quant": quant})
|
|
kwargs.setdefault("tasks", "quant")
|
|
kwargs.setdefault("calib", 16)
|
|
|
|
cmd_parts = ["scripts/huggingface_example.sh", "--no-verbose"]
|
|
if vlm:
|
|
# VLM PTQ shares the hf_ptq entry point; --vlm runs the multimodal deploy smoke test.
|
|
cmd_parts.append("--vlm")
|
|
cmd_parts = extend_cmd_parts(cmd_parts, **kwargs)
|
|
run_example_command(cmd_parts, "hf_ptq")
|