adaptive_avgpool1d_demo.py
import svetoviz_webgpu as sv
# 1. Create a 1D signal (100 samples)
t = torch.linspace(0, 10, 100)
input_tensor = (torch.sin(t) + torch.randn(100) * 0.1).unsqueeze(0).unsqueeze(0)
# 2. Define AdaptiveAvgPool1d
# Reduces the signal to a fixed length of 16 by averaging sub-regions
adap_avg_pool1d = nn.AdaptiveAvgPool1d(output_size=16)
def terminal_callback(buffer, message, images, files):
# 3. Process the sequence
output = adap_avg_pool1d(input_tensor)
buffer.send_system_message(f"Input samples: {input_tensor.shape[-1]}")
buffer.send_system_message(f"Targeting fixed mean-pooled size: 16")
buffer.send_system_message(f"Output Signal: {list(output.shape)}")
# 4. Start the interactive session
sv.pytorch_web(module=adap_avg_pool1d, terminal_callback=terminal_callback)