Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

LocalBackend/Unsloth: gradient_accumulation_steps > 1 hangs the trainer (producer waits for one result per sequence)

Aperta
#1,121 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
15/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

The hang is in the producer loop of run_unsloth_rl_training in art/unsloth/train.py, which pairs each inputs_queue put with a results_queue get, and in _async_prepare_inputs. Read how gradient_accumulation_steps reaches the trainer through TrainerArgs, then reproduce with gradient_accumulation_steps=2 to confirm the deadlock. Done means either the step runs to completion or a clear error is raised up front, and the loss weighting question in loss.py has a maintainer decision.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Versions: openpipe-art 0.5.20 (LocalBackend, Unsloth service), unsloth 2026.3.3, ART's managed vLLM runtime 0.25.1, one GPU.

What happens: with trainer_args=art.dev.TrainerArgs(per_device_train_batch_size=1, gradient_accumulation_steps=2) the first backend.train(...) call never returns. The GPU is idle; py-spy shows the trainer thread waiting for its next input in _async_prepare_inputs (inputs_queue.get()), while run_unsloth_rl_training waits for a result.

Why (as far as I can tell from art/unsloth/train.py): run_unsloth_rl_training puts one packed sequence into inputs_queue and then awaits one item from results_queue before it puts the next sequence. A result is only produced after an optimizer step. With gradient_accumulation_steps=k > 1 the Hugging Face trainer needs k inputs before it steps, so after the first input both sides wait for each other.

So gradient_accumulation_steps is accepted through TrainerArgs but cannot work with this producer loop. If it is not meant to be supported, a clear error would help.

Why it matters for long rollouts: with agent rollouts of 10-25K tokens, every trajectory fills its own packed row, and with per_device_train_batch_size=1 (memory) every trajectory becomes its own optimizer step: 32 Adam updates per train() call for 4 groups x 8 rollouts, each seeing a single trajectory with a positive or negative advantage, instead of one update over the group.

A possible fix: in run_unsloth_rl_training, put gradient_accumulation_steps sequences into the queue before awaiting one result, and pad the last batch of a step with zero-weight rows (or raise if the row count is not a multiple).

Related observation: the loss multiplies each token by weights = 1 / (trained tokens of its trajectory) and then divides by assistant_mask.sum() of the row (loss.py, policy_loss * weights * assistant_mask, then / denominator). With several trajectories per row this gives every trajectory equal weight, but with one trajectory per row its loss is effectively divided by its length twice, so long trajectories get smaller gradients than short ones. Not necessarily a bug, but it surprised me.

Happy to send a PR for the producer loop if that is the direction you prefer.

Lingua principale
Python
Stelle
10.8k
Fork
1k
Merge medio
16h 14m
PR unite (30g)
148

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di OpenPipe/ART

Tutte le issue di OpenPipe/ART

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.