group_norm_demo.py
import svetoviz_webgpu as sv
# 1. Define Layer Parameters
num_groups = 4
num_channels = 32
# num_channels must be divisible by num_groups
gn = nn.GroupNorm(num_groups=num_groups, num_channels=num_channels)
# 2. Prepare Input Tensor (Batch=1, Channels=32, H, W)
input_tensor = torch.randn(1, 32, 224, 224)
def terminal_callback(buffer, message, images, files):
output = gn(input_tensor)
buffer.send_system_message(f"Total Channels: {num_channels}")
buffer.send_system_message(f"Channels per Group: {num_channels // num_groups}")
buffer.send_system_message("Status: Effective for small batch sizes where BatchNorm fails.")
# 3. Start the interactive session
sv.pytorch_web(module=gn, terminal_callback=terminal_callback)