skills/timeseries/stateful-chunk-inference/SKILL.md
Processes long sequences in fixed-size chunks while carrying RNN hidden state across chunks for memory-efficient inference.
npx skillsauth add wenmin-wu/ds-skills timeseries-stateful-chunk-inferenceInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Long time series (days of sensor data at 5-sec intervals = 100k+ timesteps) don't fit in GPU memory as a single sequence. Split into fixed-size chunks and process sequentially, passing the hidden state from one chunk to the next. This gives the same result as processing the full sequence but with constant memory usage.
import torch
import numpy as np
def stateful_inference(model, features, chunk_size=4096, device='cuda'):
"""Run inference on long sequence in chunks, preserving hidden state.
Args:
model: RNN/GRU model that returns (predictions, hidden_state)
features: numpy array of shape (seq_len, n_features)
chunk_size: max timesteps per forward pass
"""
seq_len = len(features)
predictions = np.zeros((seq_len, model.n_classes))
hidden = None
model.eval()
with torch.no_grad():
for start in range(0, seq_len, chunk_size):
end = min(start + chunk_size, seq_len)
chunk = torch.tensor(features[start:end]).float().unsqueeze(0).to(device)
preds, hidden = model(chunk, hidden)
# Detach hidden state to prevent backprop across chunks
hidden = [h.detach() for h in hidden]
predictions[start:end] = preds.squeeze(0).cpu().numpy()
return predictions
data-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF