Skip to content

feat: Stability with fp16 for anima#2277

Merged
kohya-ss merged 1 commit intosd3from
feat-stability-with-fp16-for-anima
Feb 23, 2026
Merged

feat: Stability with fp16 for anima#2277
kohya-ss merged 1 commit intosd3from
feat-stability-with-fp16-for-anima

Conversation

@kohya-ss
Copy link
Copy Markdown
Owner

@kohya-ss kohya-ss commented Feb 23, 2026

This pull request introduces an improvement to the _forward method in library/anima_models.py to enhance numerical stability during computations involving residual connections.

Numerical stability improvements:

  • In the _forward method, input tensor x_B_T_H_W_D is now cast to float32 if its original type is float16, ensuring better numerical stability in residual connections. Each module will handle casting back to float16 as needed using an autocast context.

Address the issue described in #2274.

@kohya-ss kohya-ss changed the base branch from main to sd3 February 23, 2026 12:13
@kohya-ss kohya-ss merged commit 98a42e4 into sd3 Feb 23, 2026
3 checks passed
@kohya-ss kohya-ss deleted the feat-stability-with-fp16-for-anima branch February 23, 2026 12:15
@RedRayz
Copy link
Copy Markdown

RedRayz commented Mar 8, 2026

Even after this PR is merged, it still causing NaN losses in fp16 precision.

@kohya-ss
Copy link
Copy Markdown
Owner Author

kohya-ss commented Mar 8, 2026

Even after this PR is merged, it still causing NaN losses in fp16 precision.

Thank you for reporting. Does #2274 solve the issue?

@RedRayz
Copy link
Copy Markdown

RedRayz commented Mar 8, 2026

Yes, #2274 works fine without any problems.

@kohya-ss
Copy link
Copy Markdown
Owner Author

kohya-ss commented Mar 8, 2026

Thank you, I will investigate. If I can't find the cause, I will consider adopting #2274 as is.

@kohya-ss
Copy link
Copy Markdown
Owner Author

kohya-ss commented Apr 2, 2026

I've opened #2302, I hope this fixes the issue.

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.

2 participants