Skip to content

Fix AttributeError when pipe.dit is None during split training#1275

Open
Mr-Neutr0n wants to merge 1 commit intomodelscope:mainfrom
Mr-Neutr0n:fix-dit-none-check
Open

Fix AttributeError when pipe.dit is None during split training#1275
Mr-Neutr0n wants to merge 1 commit intomodelscope:mainfrom
Mr-Neutr0n:fix-dit-none-check

Conversation

@Mr-Neutr0n
Copy link

Summary

  • Fixes AttributeError: 'NoneType' object has no attribute 'siglip_embedder' when using split training with sft:data_process task
  • Adds explicit None check before accessing pipe.dit.siglip_embedder

Problem

When using split training as documented in Split_Training.md, the DiT model is not loaded during the first phase (data processing), but the dit attribute exists with value None.

The existing code:

if hasattr(pipe, "dit") and pipe.dit.siglip_embedder is not None:

hasattr(pipe, "dit") returns True because the attribute exists, but accessing pipe.dit.siglip_embedder fails because pipe.dit is None.

Solution

Add an explicit None check:

if hasattr(pipe, "dit") and pipe.dit is not None and pipe.dit.siglip_embedder is not None:

Test plan

  • Run split training with --task "sft:data_process" without loading the DiT model

Fixes #1246

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
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 AttributeError that arises during the data processing phase of split training. By introducing a more robust None check for the pipe.dit object, it ensures that the siglip_embedder attribute is only accessed when the DiT model is properly initialized, thereby preventing crashes and improving the stability of the training pipeline.

Highlights

  • Fix AttributeError: Resolved an AttributeError: 'NoneType' object has no attribute 'siglip_embedder' that occurred during split training with the sft:data_process task.
  • Enhanced None Check: Added an explicit pipe.dit is not None check to prevent accessing attributes on a None object when the DiT model is not loaded during the data processing phase.

🧠 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
  • diffsynth/pipelines/z_image.py
    • Added an explicit pipe.dit is not None check within the process method to prevent AttributeError when pipe.dit is None.
Activity
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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:

@Mr-Neutr0n
Copy link
Author

hi, following up — this fixes an AttributeError crash when pipe.dit is None during split training. let me know if the approach looks ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeError: 'NoneType' object has no attribute 'siglip_embedder'

1 participant