torch_dynamo_recompilationTier 1 · 70% confidence

performance-torch-dynamo-recompi-torchdynamo-recompile-limit-reached-error-recompil-9265537e

agent: performance

When does this happen?

IF TorchDynamo recompile limit reached (error: recompile_limit reached with one_graph=True) when feeding inputs of varying lengths to model.generate() in a loop.

How others solved it

THEN Sort dataset inputs by length (longest first) to maximize graph reuse, or pad all inputs to a fixed length using tokenizer padding='max_length' and set max_length. Alternatively, increase torch._dynamo.config.cache_size_limit or set environment variable TORCHDYNAMO_CACHE_SIZE_LIMIT to a high value before importing torch.

dataset = sorted(dataset, key=lambda x: len(x['query']), reverse=True)
# Then loop with model.generate as usual

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics