trl icon indicating copy to clipboard operation
trl copied to clipboard

Can gold_trainer support privileged context?

Open zouYC2021 opened this issue 6 months ago • 4 comments

Current gold_trainer(trl/experimental/gold/gold_trainer.py) seems to only support distillation between students and teachers that have the same input. I wonder whether it can support teacher model with privileged context as in sdft_trainer.

zouYC2021 avatar May 09 '26 08:05 zouYC2021

It's not supported right now. The GOLD trainer assumes symmetric inputs. Supporting privileged context would mean allowing separate teacher/student inputs in the batch and running the two forward passes independently before computing KL, similar to what sdft_trainer does. Would be a reasonable addition.

Not a trivial change (data collator + forward pass split) but well-scoped with sdft_trainer as reference. Happy to take a stab at it if there's interest.

matdou avatar May 11 '26 14:05 matdou

It's not supported right now. The GOLD trainer assumes symmetric inputs. Supporting privileged context would mean allowing separate teacher/student inputs in the batch and running the two forward passes independently before computing KL, similar to what sdft_trainer does. Would be a reasonable addition.

Not a trivial change (data collator + forward pass split) but well-scoped with sdft_trainer as reference. Happy to take a stab at it if there's interest.

That would be quite nice if someone can try that.

zouYC2021 avatar May 11 '26 20:05 zouYC2021

Hi, I’d like to take a scoped pass at this if maintainers are open.

To keep the first PR reviewable, I am planning to start off with text/off-policy GOLD only:

  • preserve the current symmetric student/teacher input path as default
  • add an opt-in privileged-context teacher path, similar in spirit to SDFT
  • student forward uses the normal prompt/completion
  • teacher forward uses prompt + privileged context + same completion
  • no vLLM teacher-server, VLM, or cross-tokenizer expansion unless yall prefer it
  • add focused tests proving teacher inputs differ while existing behavior is unchanged

Does that scope sound acceptable?

eshwanthkartitr avatar Jul 08 '26 08:07 eshwanthkartitr

Hi @eshwanthkartitr, thanks for the offer! The scope looks good, and I agree with anchoring on SDFT. A few requirements up front so this stays consistent with the rest of the codebase (we're also working on the same feature for DistillationTrainer, so the two implementations should share one config surface):

Reuse SDFT's config API instead of inventing a new one:

  • use_privileged_context: bool = False as the opt-in flag.
  • teacher_prompt_template: str | None. The template must contain {prompt} (the student's original user text). It may contain {privileged_context}, sourced per-example from a dataset column (privileged_context_column: str = "privileged_context"). Default template when unset: "{prompt}\n\n{privileged_context}".

Two behavioral details that matter for correctness:

  • Rewrite the last user turn and re-apply the chat template to avoid concatenating raw prompt text. System/tool/assistant turns must pass through untouched.
  • The teacher prompt is never truncated: privileged context doesn't count against max_prompt_length. Truncating it can cut the completion adrift from the context that justifies it.

Something to keep in mind for the tests, which we are finding useful for the DistillationTrainer, is that completion tokens must be byte-identical between the student and teacher. Only the prompt-side tokenization should differ. Your tests should assert exactly that (teacher prompt differs, completion token IDs identical), plus that default behavior is bit-for-bit unchanged.

The scope sounds good, but fail loudly:

  • GOLD defaults to lmbda=0.5, so "off-policy only" excludes the default config. Please raise a ValueError in config validation for use_privileged_context=True with lmbda > 0 or seq_kd=True. Silently training with a misaligned teacher on on-policy slices is the failure mode we most want to avoid. On-policy support can come in a follow-up (it needs the teacher to prompt tensors carried through the collator and the teacher batch rebuilt after generation).
  • Same for use_uld_loss=True: validate-error rather than ignore. (Cross-tokenizer support is actually a natural follow-up since that path already rebuilds teacher inputs from text, but let's keep it out of this PR.)

Tag me on the PR when you have it ready. Happy to review it :)

cmpatino avatar Jul 14 '26 09:07 cmpatino