Fix AttributeError when pipe.dit is None during split training#1275
Fix AttributeError when pipe.dit is None during split training#1275Mr-Neutr0n wants to merge 1 commit intomodelscope:mainfrom
Conversation
When using split training with 'sft:data_process' task, the DiT model is not loaded but the attribute 'dit' exists with value None. The existing hasattr check returns True but then accessing siglip_embedder fails. Add an explicit None check before accessing pipe.dit.siglip_embedder. Fixes modelscope#1246
Summary of ChangesHello @Mr-Neutr0n, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly fixes an AttributeError that occurs during split training when pipe.dit is None. The added None check prevents the error. I've suggested a minor simplification to the conditional statement for better readability and to remove a redundant check.
| def process(self, pipe: ZImagePipeline, prompt, edit_image): | ||
| pipe.load_models_to_device(self.onload_model_names) | ||
| if hasattr(pipe, "dit") and pipe.dit.siglip_embedder is not None: | ||
| if hasattr(pipe, "dit") and pipe.dit is not None and pipe.dit.siglip_embedder is not None: |
There was a problem hiding this comment.
The added pipe.dit is not None check is correct and fixes the bug. However, since dit is always an attribute of the ZImagePipeline instance (initialized to None in __init__), the hasattr(pipe, "dit") check is redundant. You can simplify this condition for better readability.
| if hasattr(pipe, "dit") and pipe.dit is not None and pipe.dit.siglip_embedder is not None: | |
| if pipe.dit is not None and pipe.dit.siglip_embedder is not None: |
|
hi, following up — this fixes an AttributeError crash when pipe.dit is None during split training. let me know if the approach looks ok |
Summary
sft:data_processtaskpipe.dit.siglip_embedderProblem
When using split training as documented in Split_Training.md, the DiT model is not loaded during the first phase (data processing), but the
ditattribute exists with valueNone.The existing code:
hasattr(pipe, "dit")returnsTruebecause the attribute exists, but accessingpipe.dit.siglip_embedderfails becausepipe.ditisNone.Solution
Add an explicit None check:
Test plan
--task "sft:data_process"without loading the DiT modelFixes #1246