[OMNIML-3624] ModelOpt unified entry point, WIP placeholder#1017
[OMNIML-3624] ModelOpt unified entry point, WIP placeholder#1017shengliangxu wants to merge 1 commit intomainfrom
Conversation
This change is to add a placeholder CLI: nv-modelopt. We will gradually integrate the model optimization pipelines currently scattered in many example scripts into this CLI tool. Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
📝 WalkthroughWalkthroughEstablishes CLI infrastructure for Nvidia Model Optimizer by adding license headers and module documentation to the CLI package init file, creating a new placeholder CLI entrypoint module with a main function, and registering a console script entry point in project configuration. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@modelopt/cli/nv_modelopt.py`:
- Around line 19-27: Replace the placeholder print in main() with a minimal
argparse-based CLI: import argparse, create ArgumentParser(description=...), add
at least a --version/--help flag (or a dummy subcommand) so users get standard
help, call parser.parse_args() (not parse_known_args) so unknown flags raise an
error and exit, and use the parsed args to either print the placeholder message
or version; update the public main() function to perform this parsing before
printing so --help and invalid flags behave correctly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 230149fd-61c1-46e5-9c2f-946194de0d0d
📒 Files selected for processing (3)
modelopt/cli/__init__.pymodelopt/cli/nv_modelopt.pypyproject.toml
| def main() -> None: | ||
| """Program entry point for the nv-modelopt CLI.""" | ||
| print( | ||
| "Nvidia Model Optimizer (modelopt) Unified CLI Tool! This is currently a placeholder. The functionality is WIP." | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# Find and read the target file
find . -name "nv_modelopt.py" -type f | head -5Repository: NVIDIA/Model-Optimizer
Length of output: 95
🏁 Script executed:
# Check pyproject.toml for entry points
if [ -f pyproject.toml ]; then
grep -A 10 "\[project.scripts\]" pyproject.toml
fiRepository: NVIDIA/Model-Optimizer
Length of output: 289
🏁 Script executed:
# Search for any argparse or sys.argv usage in the cli directory
rg "argparse|sys\.argv" modelopt/cli/ --type pyRepository: NVIDIA/Model-Optimizer
Length of output: 48
🏁 Script executed:
# Read the nv_modelopt.py file to see the actual implementation
cat -n ./modelopt/cli/nv_modelopt.pyRepository: NVIDIA/Model-Optimizer
Length of output: 1247
🏁 Script executed:
# Check if there's a cli module init file
cat -n ./modelopt/cli/__init__.py 2>/dev/null || echo "No __init__.py or file not found"Repository: NVIDIA/Model-Optimizer
Length of output: 910
Add argument parsing to reject invalid flags and provide help output.
main() is the public CLI entry point for nv-modelopt but doesn't parse sys.argv. This means nv-modelopt --help and invalid flags both silently collapse to the placeholder message, providing a poor user experience and failing to follow standard CLI conventions. Add a minimal argparse stub to parse arguments, provide proper help output, and fail fast on unknown flags.
Suggested implementation
+import argparse
+
-def main() -> None:
+def main() -> int:
"""Program entry point for the nv-modelopt CLI."""
+ parser = argparse.ArgumentParser(
+ prog="nv-modelopt",
+ description="NVIDIA Model Optimizer unified CLI.",
+ )
+ parser.parse_args()
print(
"Nvidia Model Optimizer (modelopt) Unified CLI Tool! This is currently a placeholder. The functionality is WIP."
)
+ return 0
if __name__ == "__main__":
- main()
+ raise SystemExit(main())🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@modelopt/cli/nv_modelopt.py` around lines 19 - 27, Replace the placeholder
print in main() with a minimal argparse-based CLI: import argparse, create
ArgumentParser(description=...), add at least a --version/--help flag (or a
dummy subcommand) so users get standard help, call parser.parse_args() (not
parse_known_args) so unknown flags raise an error and exit, and use the parsed
args to either print the placeholder message or version; update the public
main() function to perform this parsing before printing so --help and invalid
flags behave correctly.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1017 +/- ##
==========================================
- Coverage 71.73% 70.11% -1.63%
==========================================
Files 211 220 +9
Lines 23949 25240 +1291
==========================================
+ Hits 17181 17698 +517
- Misses 6768 7542 +774 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
What does this PR do?
This change is to add a placeholder CLI: nv-modelopt.
We will gradually integrate the model optimization pipelines currently scattered in many example scripts into this CLI tool.
Usage
Testing
nv-modelopt
Summary by CodeRabbit
nv-modeloptcommand-line interface, now available as a console entry point.