InstanceNorm1d

https://pytorch.org/docs/stable/generated/torch.nn.InstanceNorm1d.html

instancenorm1d_demo.py
import svetoviz_webgpu as sv

# 1. Define Layer Parameters
num_features = 128
# affine=True: Includes learnable weight and bias (gamma and beta)
in1d = nn.InstanceNorm1d(num_features=num_features, affine=True)

# 2. Prepare Input Tensor (Batch=8, Channels=128, Length=10)
input_tensor = torch.randn(8, num_features, 10)

def terminal_callback(buffer, message, images, files):
    output = in1d(input_tensor)

    buffer.send_system_message(f"Input Shape: {list(input_tensor.shape)}")
    buffer.send_system_message("Logic: Normalization applied per-channel per-sample.")
    buffer.send_system_message("Result: Mean 0 and Var 1 for each (N, C) pair.")

# 3. Start the interactive session
sv.pytorch_web(module=in1d, terminal_callback=terminal_callback)
Per-Instance Normalization
InstanceNorm1d activations
Instance Normalization is similar to Layer Normalization but goes a step further by normalizing each channel within each sample independently. This removes instance-specific contrast information, which is highly effective in sequence modeling where global style varies between samples.