bridge.models.qwen.modeling_qwen4_exp.norms#
Grouped RMSNorm with optional fused kernels and bounded FP32 backward.
Module Contents#
Classes#
Functions#
Budget eight row-width FP32 intermediates, excluding required output gradients. |
|
Limit FP32 partials to the budget and about two resident programs per SM. |
|
Normalize streams with zero-centered gains and chunked backward reductions. |
Data#
API#
- bridge.models.qwen.modeling_qwen4_exp.norms._WORKSPACE_BYTES#
None
- bridge.models.qwen.modeling_qwen4_exp.norms._can_use_triton(x: torch.Tensor, weight: torch.Tensor) bool#
- bridge.models.qwen.modeling_qwen4_exp.norms.norm_chunk_rows(width: int, workspace_bytes: int) int#
Budget eight row-width FP32 intermediates, excluding required output gradients.
A single row is the minimum allocation when its width exceeds the budget.
- bridge.models.qwen.modeling_qwen4_exp.norms._backward_partitions(
- rows: int,
- width: int,
- groups: int,
- workspace_bytes: int,
- multiprocessors: int,
Limit FP32 partials to the budget and about two resident programs per SM.
- class bridge.models.qwen.modeling_qwen4_exp.norms._GroupedRMSNorm#
Bases:
torch.autograd.Function- static forward(
- ctx: torch.autograd.function.FunctionCtx,
- x: torch.Tensor,
- weight: torch.Tensor,
- groups: int,
- eps: float,
- workspace_bytes: int,
- static backward(
- ctx: torch.autograd.function.FunctionCtx,
- grad_output: torch.Tensor,
- bridge.models.qwen.modeling_qwen4_exp.norms.grouped_rmsnorm(
- x: torch.Tensor,
- weight: torch.Tensor,
- groups: int,
- eps: float,
- *,
- workspace_bytes: int = _WORKSPACE_BYTES,
Normalize streams with zero-centered gains and chunked backward reductions.
Saves the activation and one FP32 inverse RMS per stream instead of the token-sized FP32 products that eager autograd retains. Weight gradients accumulate in FP32; chunking changes only their reduction order. Contiguous CUDA inputs optionally use Triton kernels, whose FP32 reduction orders can differ from the eager fallback. Backward always uses the saved rstd, with deterministic FP32 weight-gradient partials bounded by the workspace budget.