Diffusion export bug fixed for model_index.json#901
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughEnhanced the model_index.json handling for Diffusers pipeline exports by introducing a multi-step fallback approach: first attempting to preserve the original model_index.json from the pipeline's source location, then falling back to native Diffusers serialization, and finally synthesizing a minimal configuration using exported components. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
modelopt/torch/export/unified_export_hf.py (1)
935-940: Add a comment clarifying that Hub IDs are silently skipped.
pipe.name_or_pathis often a HuggingFace Hub model ID (e.g.,"runwayml/stable-diffusion-v1-5").Path(hub_id) / "model_index.json"is a relative path;.exists()will returnFalse, so the copy is correctly skipped. A brief inline note would make the intent obvious to future readers and prevent accidental "fixes" that break the graceful pass-through.📝 Suggested clarification
- # Prefer preserving the original model_index.json when the source is local. - if source_path: + # Prefer preserving the original model_index.json when the source is a local directory. + # Hub IDs (e.g. "runwayml/stable-diffusion-v1-5") are not local paths and will be + # skipped by the .exists() check below. + if source_path:🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@modelopt/torch/export/unified_export_hf.py` around lines 935 - 940, Add an inline comment near the is_diffusers_pipe block (around model_index_path and source_path) explaining that pipe.name_or_path may be a HuggingFace Hub ID (e.g., "runwayml/stable-diffusion-v1-5") which, when combined with Path(hub_id) results in a relative path so .exists() will be False and the copy is intentionally skipped; reference the symbols is_diffusers_pipe, model_index_path, source_path, and pipe.name_or_path in the comment so future readers understand the silent passthrough behavior and don’t try to "fix" it.
🤖 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/torch/export/unified_export_hf.py`:
- Around line 942-953: When a partial export is requested (i.e., `components` is
not None), avoid writing an unfiltered `model_index.json` from the original
`source_path` or via `pipe.save_config(export_dir)` because those list all
original pipeline components and will reference missing subdirectories; change
the logic in `unified_export_hf.py` around the blocks that check `if
source_path:` (the `candidate_model_index` read/write) and `if not
model_index_path.exists() and hasattr(pipe, "save_config"):` to first check
whether `components` is None (or otherwise only allow these fallbacks when doing
a full export), and when `components` is provided let the existing synthesized
path that uses `get_diffusion_components(pipe, components)` / `all_components`
produce the `model_index.json` instead.
---
Nitpick comments:
In `@modelopt/torch/export/unified_export_hf.py`:
- Around line 935-940: Add an inline comment near the is_diffusers_pipe block
(around model_index_path and source_path) explaining that pipe.name_or_path may
be a HuggingFace Hub ID (e.g., "runwayml/stable-diffusion-v1-5") which, when
combined with Path(hub_id) results in a relative path so .exists() will be False
and the copy is intentionally skipped; reference the symbols is_diffusers_pipe,
model_index_path, source_path, and pipe.name_or_path in the comment so future
readers understand the silent passthrough behavior and don’t try to "fix" it.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #901 +/- ##
=======================================
Coverage 73.52% 73.52%
=======================================
Files 205 205
Lines 22013 22013
=======================================
Hits 16185 16185
Misses 5828 5828 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Looking at this PR, it's fixing a bug in the Diffusers export flow for Summary of ChangesThe fix implements a three-tier fallback strategy when saving
Issues Identified1. Redundant config check (unnecessary)The last-resort synthesis at the end has an extra 2. Missing
|
Edwardf0t1
left a comment
There was a problem hiding this comment.
LGTM, left a comment, please check other reviews as well.
There was a problem hiding this comment.
Does model_index.json also include scalers, e.g., weight_scale, input_scale for the exported checkpoint?
There was a problem hiding this comment.
No, it doesn’t. The model_index.json in Diffusers only indicates which model belongs to which class, and some special pipeline parameters.
What does this PR do?
Type of change: Bug fix
Overview:
Updated diffusers export to preserve the original model_index.json instead of always rebuilding a minimal one.
The export now uses a simple fallback order: copy original model_index.json from source path if available, otherwise call
pipe.save_config(export_dir), and only then generate a minimal model_index.json as last resort.Non-diffusers export behavior is unchanged.
Usage
# Add a code snippet demonstrating how to use thisTesting
Before your PR is "Ready for review"
Additional Information
Summary by CodeRabbit