You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Move the MLflow wiring into example_utils and simplify the flag handling
hf_ptq.py is down from ~90 lines of tracking glue to three calls:
add_mlflow_args(parser), resolve_mlflow_args(args, parser) and
`with mlflow_run(args):`. Everything that knows about the flags, the
params, the tags and the summary paths now sits beside the other hf_ptq
helpers in example_utils.
Simplify how the URI is settled. Provenance is now just "did the user type
the flag", read before the fallback, so the whole thing is one assignment
and one branch:
args.mlflow_required = args.mlflow is not None
args.mlflow = args.mlflow or os.environ.get("MLFLOW_TRACKING_URI") or None
Dropping nargs="?" is what makes that work. The bare --mlflow form meant
"use $MLFLOW_TRACKING_URI", which is now what happens with no flag at all,
so it was redundant -- and it was the only source of the empty-string case
that forced the three-way logic. A bare --mlflow now gets argparse's own
"expected one argument".
Move the MLflow section of the README to the end, per review: it is a lot
of detail to meet before the feature examples like AutoQuantize. Added to
the contents table so it stays findable.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Chenjie Luo <chenjiel@nvidia.com>
Copy file name to clipboardExpand all lines: examples/hf_ptq/README.md
+56-55Lines changed: 56 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,7 @@ This section focuses on Post-training quantization, a technique that reduces mod
19
19
| Evaluate Accuracy | Evaluate your model's accuracy! |\[[Link](#evaluate-accuracy)\]||
20
20
| Exporting Checkpoints | Export to Hugging Face Unified Checkpoint and deploy on TRT-LLM/vLLM/SGLang |\[[Link](#exporting-checkpoints)\]|\[[docs](https://nvidia.github.io/Model-Optimizer/deployment/3_unified_hf.html)\]|
21
21
| Pre-Quantized Checkpoints | Ready to deploy Hugging Face pre-quantized checkpoints |\[[Link](#pre-quantized-checkpoints)\]||
22
+
| Tracking runs with MLflow | Record a PTQ run on an MLflow server so it can be reproduced from its entry alone |\[[Link](#tracking-runs-with-mlflow)\]||
22
23
| Resources | Extra links to relevant resources |\[[Link](#resources)\]||
The tracking itself lives in `modelopt.torch.utils.mlflow`
344
-
([`MlflowRunLogger`](../../modelopt/torch/utils/mlflow.py)), so other example scripts can
345
-
record runs the same way; `hf_ptq.py` only supplies the params and artifacts specific to PTQ.
346
-
347
-
> Note: only the main rank uploads, so `--use_fsdp2` runs produce a single run. The log
348
-
> captures Python output; output written directly by native libraries (NCCL, CUDA) goes to
349
-
> the terminal only. On SLURM, keep the job's own `.out` file for those.
350
-
351
297
### Megatron-Bridge Example Script
352
298
353
299
Please refer to [examples/megatron_bridge/README.md](../megatron_bridge/README.md) for example scripts for PTQ / QAD with Megatron-Bridge which is generally more performant than the Hugging Face scripts.
@@ -693,6 +639,61 @@ After the TensorRT-LLM checkpoint export, you can use the `trtllm-build` build c
693
639
- Deployable on [TensorRT-LLM](https://github.com/NVIDIA/TensorRT-LLM), [vLLM](https://github.com/vllm-project/vllm) and [SGLang](https://github.com/sgl-project/sglang)
694
640
- More models coming soon!
695
641
642
+
## Tracking runs with MLflow
643
+
644
+
Set MLflow's own `MLFLOW_TRACKING_URI`, or pass `--mlflow <tracking-uri>`, to record a PTQ
645
+
run on an MLflow server so it can be reproduced later from its MLflow entry alone:
646
+
647
+
```bash
648
+
python hf_ptq.py \
649
+
--pyt_ckpt_path <huggingface_model_card> \
650
+
--recipe general/ptq/nvfp4_default-kv_fp8_cast \
651
+
--export_path <quantized_ckpt_path> \
652
+
--mlflow https://<your-mlflow-server>/
653
+
```
654
+
655
+
The run is opened *before* the model loads, so a bad URI or a missing token fails within
656
+
seconds rather than after a full calibration.
657
+
658
+
<details>
659
+
<summary>Uploaded artifacts</summary>
660
+
661
+
| Artifact | Contents |
662
+
| --- | --- |
663
+
| `command.txt` | The full invocation, copy-pasteable, with credentials masked |
664
+
| `version.txt` | The ModelOpt version that ran |
665
+
| `recipe/resolved_recipe.yaml` | The `--recipe` with its `$import`s expanded, so it stands alone |
666
+
| `logs/hf_ptq.log` | The run's Python stdout/stderr, including the traceback if it crashed |
667
+
| `summary/quant_summary.txt` | The per-quantizer summary (unless `--no-verbose`) |
668
+
| `summary/moe.html` | Per-expert calibration token counts, when the run produces them |
669
+
670
+
</details>
671
+
672
+
Every command-line argument is also logged as a searchable param, alongside
673
+
`user`/ `hostname` / `modelopt_version` / `git_sha` tags. A run that fails is
674
+
still recorded, with status `FAILED` and its log attached.
675
+
676
+
Other flags:
677
+
678
+
- `--mlflow_experiment`— defaults to `$USER/hf_ptq/<checkpoint basename>-<recipe name>`,
679
+
falling back to `--qformat` when no `--recipe` is used.
680
+
- `--mlflow_run_name`— defaults to the UTC start time, `YYYYmmdd-HHMMSS`.
681
+
- `$MLFLOW_TRACKING_URI`enables tracking on its own; `--mlflow` overrides it. A URI taken
682
+
from the environment is best-effort — if the client is missing or the server is
683
+
unreachable the run warns and continues untracked, since the variable is often exported
684
+
for other tooling. An explicit `--mlflow` fails loudly instead.
685
+
686
+
Authentication uses MLflow's own environment variables (`MLFLOW_TRACKING_TOKEN`, or
0 commit comments