add support for Liger Kernel (#858)

* add support for Liger Kernel

* don't use Liger Kernel for loss

* Revert holdover changes to train.py from Liger Kernel loss compute

revert spacing

...

...

* move AutoModelForCausalLM to top of model.py

* remove Liger Kernel+GSPO validation check

* Simplify get_model with model_cls var
This commit is contained in:
celeste
2025-08-30 22:06:59 -07:00
committed by GitHub
parent d127cbaf9e
commit f83079bdb1
3 changed files with 13 additions and 7 deletions
+7
View File
@@ -68,6 +68,13 @@ class ModelConfig(BaseConfig):
),
] = 1
liger_kernel: Annotated[
bool,
Field(
description="Whether to use Liger Kernel.",
),
] = False
@model_validator(mode="after")
def _map_model_name_for_moe(self):
"""Map model name if it exists in MOE_MODEL_MAPS."""
+5 -6
View File
@@ -5,14 +5,11 @@ import torch.distributed as dist
import torch.nn as nn
from beartype import beartype as typechecker
from jaxtyping import Float, Int, jaxtyped
from liger_kernel.transformers import AutoLigerKernelForCausalLM
from torch import Tensor
from torch.distributed.algorithms._checkpoint.checkpoint_wrapper import checkpoint_wrapper
from torch.distributed.fsdp import FSDPModule, MixedPrecisionPolicy, fully_shard
from transformers import (
AutoConfig,
AutoModelForCausalLM,
AutoTokenizer,
)
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
from transformers.tokenization_utils import PreTrainedTokenizer
from prime_rl.trainer.config import ActivationCheckpointConfig, ModelConfig
@@ -53,7 +50,9 @@ def get_model(config: ModelConfig) -> nn.Module:
config.name, attn_implementation=config.attn, trust_remote_code=config.trust_remote_code
)
config_model.use_cache = False
model = AutoModelForCausalLM.from_pretrained(
model_cls = AutoLigerKernelForCausalLM if config.liger_kernel else AutoModelForCausalLM
model = model_cls.from_pretrained(
pretrained_model_name_or_path=config.name,
config=config_model,
trust_remote_code=config.trust_remote_code,
+1 -1
View File
@@ -164,4 +164,4 @@ class RLTrainerConfig(BaseSettings):
def disable_logging_wandb_samples(self):
if self.monitor.wandb and self.monitor.wandb.log_extras:
self.monitor.wandb.log_extras.samples = False
return self
return self