Skip to content

Commit a56b6f3

Browse files
authored
Use os.path.join for quant_summary path (#1001)
### What does this PR do? Type of change: Bug fix I'm seeing the error ``` Error saving quant summary: [Errno 2] No such file or directory: '/home/chad/checkpoint//.quant_summary.txt' ``` when using a trailing slash in the `export_path` to `hf_ptq.py`. ### Testing This fix will work for all cases of with and without trailing slash, and both `str` and `Path`. ``` cvoegele@nvdilw8aur4dw1a:~>> python >>> os.path.join("/home/chad/output", "a.txt") '/home/chad/output/a.txt' >>> os.path.join("/home/chad/output/", "a.txt") '/home/chad/output/a.txt' >>> os.path.join(Path("/home/chad/output"), "a.txt") '/home/chad/output/a.txt' >>> os.path.join(Path("/home/chad/output/"), "a.txt") '/home/chad/output/a.txt' ``` ### Before your PR is "*Ready for review*" Make sure you read and follow [Contributor guidelines](https://github.com/NVIDIA/Model-Optimizer/blob/main/CONTRIBUTING.md) and your commits are signed (`git commit -s -S`). Make sure you read and follow the [Security Best Practices](https://github.com/NVIDIA/Model-Optimizer/blob/main/SECURITY.md#security-coding-practices-for-contributors) (e.g. avoiding hardcoded `trust_remote_code=True`, `torch.load(..., weights_only=False)`, `pickle`, etc.). - Is this change backward compatible?: ✅ - If you copied code from any other sources or added a new PIP dependency, did you follow guidance in `CONTRIBUTING.md`: ✅ - Did you write any new necessary tests?: ✅ - Did you update [Changelog](https://github.com/NVIDIA/Model-Optimizer/blob/main/CHANGELOG.rst)?: N/A <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Improved internal path handling for quantization summary output to enhance cross-platform compatibility. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Signed-off-by: Chad Voegele <cvoegele@nvidia.com>
1 parent 1d6ec89 commit a56b6f3

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

modelopt/torch/quantization/model_quant.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import fnmatch
1919
import inspect
20+
import os
2021
import warnings
2122
from collections.abc import Callable, Iterable
2223
from typing import Any
@@ -519,11 +520,7 @@ def print_quant_summary(model: nn.Module, output_dir: str | None = None):
519520
lines.append(f"{len(lines)} TensorQuantizers found in model")
520521

521522
if output_dir:
522-
path = (
523-
output_dir.joinpath(".quant_summary.txt")
524-
if hasattr(output_dir, "joinpath")
525-
else f"{output_dir}/.quant_summary.txt"
526-
)
523+
path = os.path.join(output_dir, ".quant_summary.txt")
527524
with open(path, "w", encoding="utf-8") as f:
528525
f.write("\n".join(lines) + "\n")
529526
print(f"\033[1mQuant summary saved to {path}\033[0m")

0 commit comments

Comments
 (0)