Skip to content

feat: Stability with fp16 for anima#2277

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

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

Conversation

@kohya-ss

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

Copy link
Copy Markdown
Owner

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

RedRayz commented Mar 8, 2026

Copy link
Copy Markdown

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

@kohya-ss

kohya-ss commented Mar 8, 2026

Copy link
Copy Markdown
Owner Author

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

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

@RedRayz

RedRayz commented Mar 8, 2026

Copy link
Copy Markdown

Yes, #2274 works fine without any problems.

@kohya-ss

kohya-ss commented Mar 8, 2026

Copy link
Copy Markdown
Owner Author

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

@kohya-ss

kohya-ss commented Apr 2, 2026

Copy link
Copy Markdown
Owner Author

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