Skip to content

cosmos3: speed (wip for #2) - #3

Merged
LeoBorcherding merged 1 commit into
cosmos3-sim-transferfrom
cosmos3-sim-transfer-wip
Nov 6, 2026
Merged

LeoBorcherding merged 1 commit into
cosmos3-sim-transferfrom
cosmos3-sim-transfer-wip

Conversation

@LeoBorcherding

Copy link
Copy Markdown
Owner

Iteration branch for #2 (speed). Once Codex is clean here, this commit goes to cosmos3-sim-transfer in one push.

  • The cached KV history is kept as [d, tokens, kv_heads], the layout flash attention reads. Before, K was stored as [d, kv_heads, tokens] and permuted back with a full copy every forward, and V was permuted inside attention_ext the same way. attention_ext also skips a same-type F16 cast, which is a full copy for K/V that are already contiguous F16.
  • ggml-patches/0014: CUDA concat of fully contiguous tensors launched one kernel per ne3 slice. The Wan VAE concatenates its causal cache over the channel dim, so a 121-frame decode made about 1.5M concat launches (nsys). One grid-stride launch now covers every slice.

Colab G4 (RTX PRO 6000 Blackwell), Linux, CUDA 13.0, 832x480, 121 frames, seed 2025, two runs each:

e6a98b1 a8345e5
transformer, NVIDIA's example 2 15.89 / 15.83 s (7.62 / 7.64 fps) 12.84 / 12.84 s (9.42 fps)
VAE decode 14.34 / 14.31 s 10.19 / 10.19 s
rally car clip, control encode + transformer + decode 35.6 / 35.5 s 27.6 / 27.6 s
PSNR against NVIDIA's reference, mean / worst frame 37.92 / 36.98 dB 37.92 / 36.98 dB

The output is bit-identical to e6a98b1 (same latents and frames, max abs diff 0).

…-launch CUDA concat

Each forward copied the whole cached history twice per layer: K was stored as
[d, kv_heads, tokens] and permuted back for attention, and V was permuted inside
attention_ext. Storing both as [d, tokens, kv_heads] makes the history concat a
single contiguous copy and the attention inputs views. attention_ext also skips
the same-type F16 cast, a full copy for K/V that are already contiguous F16.

ggml-patches/0014: CUDA concat of fully contiguous tensors launched one kernel
per ne3 slice; the Wan VAE concatenates its causal cache over the channel dim,
which made about 1.5M launches per 121-frame decode. One grid-stride launch now
covers every slice.
@LeoBorcherding

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T18:13:20.659912Z a8345e5 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: a8345e5ed5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

1 participant