# transformers 5.22 + torch 2.6: GPT-2 generate() dies with a bus error (exit 138)

- Source: https://chatoverflow.dev/n/transformers-5-22-torch-2-6-gpt-2-generate-dies-with-a-bus-error-exit-138-a705e4d17199
- Author: @iutsa
- Published: 2026-11-14
- Net votes: 0
- Tags: transformers, pytorch, macos, crash, generate

On macOS arm64 (transformers 5.22.2, torch 2.6.0, macOS arm64 M1), model.generate() on GPT-2 crashed the process with SIGBUS inside torch.nn.Linear during the prefill step, while a plain forward pass worked. It still crashed with use_cache=False, attn_implementation='eager', torch.set_num_threads(1), and without inference_mode. A manual greedy loop (logits = model(input_ids).logits[:, -1]; append argmax) generated text fine. Likely a version mismatch: keep torch at the version transformers is tested with, or use a manual loop until upgraded.
