Skip to content

[Kumo-Anomaly 3/n] Support post-norm and dropout in TransformerBlock - #1106

Draft
aw471 wants to merge 2 commits into
mainfrom
anomaly-block-sdm-transformerblock
Draft

aw471 wants to merge 2 commits into
mainfrom
anomaly-block-sdm-transformerblock

Conversation

@aw471

@aw471 aw471 commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds optional post-norm to TransformerBlock, through attn_residual_norm after the attention residual and mlp_residual_norm after the feedforward residual, and applies dropout to the attention output in training. Kumo-Anomaly's ResidualBlock now builds on a KumoAnomalyTransformerBlock instead of torch.nn.TransformerEncoderLayer.

Description of the change

Both norms apply on the eager and the in-place out= paths. mlp_residual_norm applies only when mlp is set, and passing it without mlp raises. dropout reuses the attention-weight dropout from #1084 and, as in torch.nn.TransformerEncoderLayer, also drops the attention output before the residual addition. The compiled, non-contiguous out= path rounds the feedforward residual to the dtype of out before mlp_residual_norm, so eager and compiled outputs agree when norms run in float32 under autocast.

KumoAnomalyTransformerBlock only configures TransformerBlock: a Linear/GELU/Dropout/Linear/Dropout feedforward, LayerNorm residual norms and torch.nn.MultiheadAttention-style initialization. The test fixture that disabled PyTorch's MHA fast path (#1105) is removed, since the block tests now compare against a sequence-first torch.nn.TransformerEncoderLayer with copied weights.

This PR is stacked on #1211 but does not depend on it.

Validation

With the released Kumo-Anomaly weights, KumoAnomalyTransformerBlock matches a torch.nn.TransformerEncoderLayer loaded with the same weights to 4.4e-16 in float64 and 2.4e-7 in float32. The compiled out= paths are covered by test/nn/test_compile.py, which runs only with FULL_TEST=1; those tests pass on CPU.

@copy-pr-bot

copy-pr-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@aw471

aw471 commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator Author

/ok to test aeb403f

@aw471
aw471 force-pushed the anomaly-block-sdm-transformerblock branch from 7873930 to 14dfd7d Compare October 20, 2026 17:53
@aw471 aw471 changed the title Support post-norm and dropout in TransformerBlock [Kumo-Anomaly 4/n] Support post-norm and dropout in TransformerBlock Oct 20, 2026
@aw471
aw471 changed the base branch from main to aw471/kumo-anomaly-model October 20, 2026 17:55
@aw471
aw471 force-pushed the anomaly-block-sdm-transformerblock branch from 14dfd7d to 802f0f8 Compare October 20, 2026 18:33
@aw471
aw471 force-pushed the aw471/kumo-anomaly-model branch from 3d184cc to 9fc900c Compare October 20, 2026 18:33
aw471 and others added 2 commits October 21, 2026 09:43
Co-authored-by: Aditi Gautam <adgautam@nvidia.com>
Add optional `attn_residual_norm` and `mlp_residual_norm` modules to `TransformerBlock`, and apply its dropout to the attention output before the residual addition. Build the Kumo-Anomaly `ResidualBlock` on a new `KumoAnomalyTransformerBlock` instead of `torch.nn.TransformerEncoderLayer`.
@aw471
aw471 force-pushed the anomaly-block-sdm-transformerblock branch from 802f0f8 to 4883c9c Compare October 21, 2026 17:07
@aw471
aw471 force-pushed the aw471/kumo-anomaly-model branch from 9fc900c to 58ef591 Compare October 21, 2026 17:07
@aw471 aw471 changed the title [Kumo-Anomaly 4/n] Support post-norm and dropout in TransformerBlock [Kumo-Anomaly 3/n] Support post-norm and dropout in TransformerBlock Oct 21, 2026
@aw471
aw471 force-pushed the anomaly-block-sdm-transformerblock branch from 4883c9c to e1c4f18 Compare October 21, 2026 17:41
@aw471
aw471 force-pushed the aw471/kumo-anomaly-model branch 2 times, most recently from ca0db9f to bd1274f Compare October 21, 2026 17:44
@aw471
aw471 force-pushed the anomaly-block-sdm-transformerblock branch from e1c4f18 to 1a21c84 Compare October 21, 2026 17:44
@aw471
aw471 force-pushed the aw471/kumo-anomaly-model branch from bd1274f to b4bb3c5 Compare October 21, 2026 20:16
@aw471
aw471 force-pushed the anomaly-block-sdm-transformerblock branch from 1a21c84 to eb80b67 Compare October 21, 2026 20:16
@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.91%. Comparing base (a3ee9a3) to head (bbf07e1).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sdm/nn/attention.py 72.22% 5 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                    @@
##           aw471/kumo-anomaly-model    #1106   +/-   ##
=========================================================
  Coverage                     82.91%   82.91%           
=========================================================
  Files                           172      172           
  Lines                         11107    11133   +26     
=========================================================
+ Hits                           9209     9231   +22     
- Misses                         1898     1902    +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@aw471
aw471 force-pushed the aw471/kumo-anomaly-model branch from b4bb3c5 to e645b2a Compare October 21, 2026 20:34
@aw471
aw471 force-pushed the anomaly-block-sdm-transformerblock branch from eb80b67 to d92932e Compare October 21, 2026 20:34
@aw471
aw471 force-pushed the aw471/kumo-anomaly-model branch from e645b2a to 1879d55 Compare October 21, 2026 21:08
@aw471
aw471 force-pushed the anomaly-block-sdm-transformerblock branch 2 times, most recently from 12dc0c1 to bbf07e1 Compare October 21, 2026 21:20
@aw471
aw471 force-pushed the aw471/kumo-anomaly-model branch 2 times, most recently from a3ee9a3 to e7233bc Compare October 21, 2026 22:05
@aw471
aw471 force-pushed the anomaly-block-sdm-transformerblock branch from bbf07e1 to 7d3adf1 Compare October 21, 2026 22:05
Base automatically changed from aw471/kumo-anomaly-model to main October 22, 2026 09:40
rusty1s added a commit that referenced this pull request Oct 22, 2026
# Summary

> Loads the released Kumo-Anomaly weights in `KumoAnomaly()`, filling in
the checkpoint TODO from #1220.

# Description of the change

> `_load_from_pretrained` loads `final_model.pth` from
`nvidia/Kumo-Anomaly` at the pinned revision, and `remap_ckpt` maps the
checkpoint's state dict onto the SDM modules for a strict load. Inside
each time and feature layer, the attention, feedforward and
residual-norm weights are renamed to `attn.qkv_lin`, `attn.out_lin`,
`mlp.0`/`mlp.3` and `attn_residual_norm`/`mlp_residual_norm`. The three
kernel-size-1 `Conv1d` projection weights are squeezed for the `Linear`
layers.
>
> The model is built on the target device rather than on `meta`. The
step embedding's sinusoidal lookup is a non-persistent buffer that the
checkpoint does not contain, so `load_state_dict(..., assign=True)`
would leave it on `meta`.
>
> The loader and key mapping come from Aditi Gautam's `ckpt.py` in
#1167. This PR is stacked on #1106.

# Validation

> CI does not download the weights, so these checks were run manually on
CPU:
>
> - All 260 checkpoint tensors load strictly.
> - Compared with #1167's pretrained `KumoAnomaly` (`num_samples=3`,
`num_steps=5`, seeded generator), scores for series of shape `[250, 5]`
and `[130, 30]` differ by at most 7.2e-7 and 1.5e-7, with identical
top-10 rows. Swapping `norm1` and `norm2` in the remap changes scores by
up to 0.52, so this comparison catches same-shape remap mistakes.
> - On a 400-step series with a level shift at steps 250-259, the
default call ranks exactly those steps highest.

---------

Co-authored-by: Aditi Gautam <adgautam@nvidia.com>
Co-authored-by: Matthias Fey <matthias.fey@tu-dortmund.de>

This branch has not been deployed

No deployments
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