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)