cross_entropy=True rebinds torch.nn.functional.cross_entropy process-wide, so unrelated 3-D or soft-target calls fail

Aperta
#1,639 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

@ArchanaChetan07 ci sta già lavorando.

Dal 19/11/2026.

  • #1657 di @ArchanaChetan07 — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
65/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, pytorch

Direzione di ricerca

Start by tracing the 20 apply_liger_kernel_to_* functions that assign nn.functional.cross_entropy, then inspect liger_cross_entropy and its tests. Compare scoping the patch to the model's loss module with falling back to the original function for unsupported inputs, such as 3-D inputs or floating-point targets. Done means unrelated valid cross-entropy calls continue to work after a model is patched, with regression coverage for the reported cases.

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

Descrizione

apply_liger_kernel_to_<model>(cross_entropy=True) replaces torch.nn.functional.cross_entropy for the whole process, not only inside the patched model. Any later F.cross_entropy call in the same process goes to Liger, including calls Liger's kernel doesn't support, and those raise:

import torch, torch.nn.functional as F
from liger_kernel.transformers import apply_liger_kernel_to_granite

x3, y3 = torch.randn(2, 7, 5), torch.randint(0, 7, (2, 5))   # (N, C, d) input: valid for F.cross_entropy
x2, soft = torch.randn(4, 7), torch.softmax(torch.randn(4, 7), -1)  # probability targets: also valid
print(F.cross_entropy(x3, y3), F.cross_entropy(x2, soft))   # both fine
apply_liger_kernel_to_granite(rope=False, rms_norm=False, swiglu=False, cross_entropy=True)
print(F.cross_entropy.__module__)                            # liger_kernel.transformers.functional
F.cross_entropy(x3, y3)    # ValueError: too many values to unpack (expected 2)
F.cross_entropy(x2, soft)  # raises here on CPU; we did not check what it does on GPU

(CPU, Liger main.) 36 of the 45 apply_liger_kernel_to_* functions set nn.functional.cross_entropy = liger_cross_entropy, so an unrelated loss in the same training script, say a distillation loss with soft targets, breaks once a model is patched.

Patching only the patched model's module reference, or having liger_cross_entropy fall back to the original function for inputs it doesn't handle (more than 2 dims, floating-point targets), would avoid it. Found in Halo, which scopes its Liger cross entropy to transformers' loss module for this reason.

Lingua principale
Python
Stelle
6.7k
Fork
668
Merge medio
4g 12h
PR unite (30g)
27

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 linkedin/Liger-Kernel

Tutte le issue di linkedin/Liger-Kernel

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.