Skip to content

float: use CK stochastic rounding cuda kernel (CORE-200)#13971

Open
rattus128 wants to merge 1 commit into
Comfy-Org:masterfrom
rattus128:prs/stochastic-kernel
Open

float: use CK stochastic rounding cuda kernel (CORE-200)#13971
rattus128 wants to merge 1 commit into
Comfy-Org:masterfrom
rattus128:prs/stochastic-kernel

Conversation

@rattus128
Copy link
Copy Markdown
Contributor

@rattus128 rattus128 commented May 19, 2026

--- PR requires release of comfy-kitchen 0.2.9 with feature ---

Local master users can test with this wheel:
https://github.com/rattus128/comfy-kitchen/actions/runs/26069217419


Use a comfy-kitchen cuda kernel for the stochastic rounding process

Comfy-Org/comfy-kitchen#40

Dynamic-VRAM does this on the fly for offloaded loras to implement fp8mm consistently whether the weight is loaded or not (and to also unify load and offload paths). It is however performance prohibitive in the offload case.

This will also improve performance a little for primary load latency (first iteration even when fully loading).

The comfy-kitchen variant does use alternate RNG to the eager implementation it replaces so seeds do move with this change.

Example test conditions:

Windows, RTX5060, 64GB
LTX2.3 T2V 720x540x5s
Second workflow run

scr

Before

got prompt
Model LTXAV prepared for dynamic VRAM loading. 23838MB Staged. 1660 patches attached. Force pre-loaded 1496 weights: 44 KB.
100%|████████████████████████████████████████████████████████████████████████████████████| 8/8 [01:17<00:00,  9.74s/it]
Model LTXAV prepared for dynamic VRAM loading. 23838MB Staged. 1660 patches attached. Force pre-loaded 1496 weights: 44 KB.
100%|████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:45<00:00, 15.22s/it]
Requested to load AudioVAE
loaded completely;  693.46 MB loaded, full load: True
0 models unloaded.
Model VideoVAE prepared for dynamic VRAM loading. 1384MB Staged. 0 patches attached.
Prompt executed in 141.87 seconds

After:

got prompt
Model LTXAV prepared for dynamic VRAM loading. 23838MB Staged. 1660 patches attached. Force pre-loaded 1496 weights: 44 KB.
100%|████████████████████████████████████████████████████████████████████████████████████| 8/8 [00:42<00:00,  5.37s/it]
Model LTXAV prepared for dynamic VRAM loading. 23838MB Staged. 1660 patches attached. Force pre-loaded 1496 weights: 44 KB.
100%|████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:27<00:00,  9.13s/it]
Requested to load AudioVAE
loaded completely;  693.46 MB loaded, full load: True
0 models unloaded.
Model VideoVAE prepared for dynamic VRAM loading. 1384MB Staged. 0 patches attached.
Prompt executed in 87.62 seconds

Regression Tests:

Linux, RTX5090, qwenImage 1328x1328 with 8 step lora (known very sensitive to stochastic rounding)

Before:

image

After:

image

Linux RTX5090, LTX2.3 T2V template ✅
Linux RTX5090, Ace-step 1.5 ✅
Linux RTX5090, Stable-cascade -> Flux2 ✅

@socket-security
Copy link
Copy Markdown

socket-security Bot commented May 19, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedglfw@​2.10.0100100100100100

View full report

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 251d2a99-d254-4fd5-9478-d5bb96f162b9

📥 Commits

Reviewing files that changed from the base of the PR and between 2811e01 and 0912fd5.

📒 Files selected for processing (2)
  • comfy/float.py
  • requirements.txt
🚧 Files skipped from review as they are similar to previous changes (2)
  • requirements.txt
  • comfy/float.py

📝 Walkthrough

Walkthrough

The PR adds runtime detection for comfy_kitchen.stochastic_rounding_fp8, supplying a fallback that raises NotImplementedError if unavailable. The FP8 branch in stochastic_rounding now, when the feature is present, creates an FP8-range RNG tensor from the existing torch.Generator and delegates rounding to comfy_kitchen; otherwise it uses the existing local implementation. The comfy-kitchen requirement is bumped to >=0.2.9.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: integrating a comfy-kitchen CUDA kernel for stochastic rounding, which is the primary objective of this PR.
Description check ✅ Passed The description provides detailed context about the changes, including performance improvements, regression testing, and references to the underlying comfy-kitchen implementation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@comfy/float.py`:
- Line 10: The except clause in comfy.float currently binds the exception to the
unused variable `e` (except (AttributeError, ImportError) as e:), which triggers
a lint error; update that except clause to stop binding the exception (use
except (AttributeError, ImportError):) so the exception is still caught but no
unused variable is created—locate the try/except block in comfy.float and remove
the "as e" from the except line.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 297e29f5-7a17-444f-a99d-e390796890d5

📥 Commits

Reviewing files that changed from the base of the PR and between df2454b and 2811e01.

📒 Files selected for processing (2)
  • comfy/float.py
  • requirements.txt

Comment thread comfy/float.py Outdated
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