"""Quick check run at the start of every Kaggle session (library versions there differ from the Mac's): with full context the streaming model must equal the original model, and one chunk at a time must equal all at once. Uses random features, so it needs no audio. test_streaming.py is the fuller check on real recitation.""" import sys import torch from streaming_model import StreamingMuaalem, download, load_muaalem @torch.no_grad() def main() -> None: torch.manual_seed(0) base = load_muaalem(download()) features = torch.randn(1, 512, 160) original = base(features) for left in (192, 384): model = StreamingMuaalem(base, left=left).eval() full, _ = model(features, torch.tensor([512]), chunk=512, left=0) at_once, _ = model(features, torch.tensor([512])) state = model.initial_state() steps = [] for start in range(0, 512, model.chunk): logits, state = model.step(features[:, start : start + model.chunk], state) steps.append(logits) a = (full - original).abs().max().item() b = (torch.cat(steps, 1) - at_once).abs().max().item() print(f"self-check, memory {left}: full context vs original {a:.1e}, step vs all at once {b:.1e}") if a > 1e-3 or b > 1e-3: sys.exit("self-check failed: the streaming model does not match") if __name__ == "__main__": main()