Adds Liger Kernel support for a new HuggingFace Transformers model, or modifies existing monkey-patching. Generates lce_forward, monkey-patch function, tests, and README entry. Use when adding a new model to Liger Kernel, when a user asks to patch an unsupported model, when extending MODEL_TYPE_TO_APPLY_LIGER_FN, or when modifying/updating/fixing an existing monkey-patch (e.g., adding a new kernel to an already-supported model, fixing instance patching, updating a patch for upstream HF changes).
Adds Liger Kernel optimization support for a new HuggingFace model, or modifies existing monkey-patching, through a staged pipeline with human review between stages. Supports creating new model patches and modifying existing ones.
Keywords that suggest modify mode: update, fix, change, add [kernel] to [existing model], extend, modify, new activation, new norm, bug in patch, upstream changed
Spawn a Model Analyzer agent (read model-analyzer.md).
The agent reads the HF modeling_*.py source and produces a answering 12 architectural questions from .
Human checkpoint: Present the profile. Confirm before proceeding.
Spawn a Code Generator agent (read code-generator.md).
Generates/modifies up to 13 files:
src/liger_kernel/transformers/model/{model}.py — NEW lce_forwardsrc/liger_kernel/transformers/monkey_patch.py — MODIFYsrc/liger_kernel/transformers/__init__.py — MODIFYsrc/liger_kernel/transformers/model/output_classes.py — MODIFY if neededtest/transformers/test_monkey_patch.py — MODIFYtest/convergence/bf16/test_mini_models.py — MODIFY (FLCE path)test/convergence/bf16/test_mini_models_with_logits.py — MODIFY (non-FLCE path)test/convergence/fp32/test_mini_models.py — MODIFY (FLCE path)test/convergence/fp32/test_mini_models_with_logits.py — MODIFY (non-FLCE path)test/convergence/bf16/test_mini_models_multimodal.py — MODIFY if VL modeltest/convergence/fp32/test_mini_models_multimodal.py — MODIFY if VL modeltest/utils.py — MODIFYREADME.md — MODIFYHuman checkpoint: Present changes for review.
Spawn a Validator agent (read validator.md).
Runs instance patching test, convergence test, and lint check. Retries up to 3 times on failure.
Human checkpoint: Report final test results.
Read the existing apply_liger_kernel_to_{model_type} function in monkey_patch.py and the relevant section of the upstream HF modeling_{model_type}.py. Produce a short change plan:
Human checkpoint: Present the change plan. Confirm before proceeding.
Spawn the Code Generator agent (read code-generator.md) in modify mode.
Human checkpoint: Present changes for review.
Spawn the Validator agent (read validator.md). This stage is mandatory — do not skip it. At minimum, run:
pytest test/transformers/test_monkey_patch.py -k "{model_type}" -xvspytest test/convergence/bf16/test_mini_models.py -k "{model_type}" -xvs (FLCE, bf16)pytest test/convergence/bf16/test_mini_models_with_logits.py -k "{model_type}" -xvs (non-FLCE, bf16)pytest test/convergence/fp32/test_mini_models.py -k "{model_type}" -xvs (FLCE, fp32)pytest test/convergence/fp32/test_mini_models_with_logits.py -k "{model_type}" -xvs (non-FLCE, fp32)pytest test/convergence/bf16/test_mini_models_multimodal.py -k "{model_type}" -xvspytest test/convergence/fp32/test_mini_models_multimodal.py -k "{model_type}" -xvsmake checkstyleHuman checkpoint: Report final test results.