Liger autopatch

From linkedin/Liger-Kernel · View interactive version

Liger autopatch is an AI agent skill from the GitHub repository linkedin/Liger-Kernel. 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_A

How to use this skill

Skill file

Liger Auto-Patch

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.

Mode Detection

Keywords that suggest modify mode: update, fix, change, add [kernel] to [existing model], extend, modify, new activation, new norm, bug in patch, upstream changed

Pipeline (Create Mode)

Stage 1: Analyze

Follow the Model Analyzer workflow in model-analyzer.md. If the host runtime supports parallel subagents, this stage may be delegated to one; otherwise execute the workflow directly.

This stage reads the HF modeling_*.py source and produces a model profile answering 12 architectural questions from decision-matrix.md.

Human checkpoint: Present the profile. Confirm before proceeding.

Stage 2: Generate

Follow the Code Generator workflow in code-generator.md.

Generates/modifies up to 13 files:

  1. src/liger_kernel/transformers/model/{model}.py — NEW lce_forward
  2. src/liger_kernel/transformers/monkey_patch.py — MODIFY
  3. src/liger_kernel/transformers/__init__.py — MODIFY
  4. src/liger_kernel/transformers/model/output_classes.py — MODIFY if needed
  5. test/transformers/test_monkey_patch.py — MODIFY
  6. test/convergence/bf16/test_mini_models.py — MODIFY (FLCE path)
  7. test/convergence/bf16/test_mini_models_with_logits.py — MODIFY (non-FLCE path)
  8. test/convergence/fp32/test_mini_models.py — MODIFY (FLCE path)
  9. test/convergence/fp32/test_mini_models_with_logits.py — MODIFY (non-FLCE path)
  10. test/convergence/bf16/test_mini_models_multimodal.py — MODIFY if VL model
  11. test/convergence/fp32/test_mini_models_multimodal.py — MODIFY if VL model
  12. test/utils.py — MODIFY
  13. README.md — MODIFY

Human checkpoint: Present changes for review.

Stage 3: Validate

Follow the Validator workflow in validator.md.

Runs instance patching test, convergence test, and lint check. Retries up to 3 times on failure.

Human checkpoint: Report final test results.

Pipeline (Modify Mode)

Stage 1: Change Impact Analysis

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.

Stage 2: Apply Changes

Follow the Code Generator workflow in code-generator.md in modify mode.

Human checkpoint: Present changes for review.

Stage 3: Validate

Follow the Validator workflow in validator.md. This stage is mandatory — do not skip it. At minimum, run:

  1. Instance patching test: pytest test/transformers/test_monkey_patch.py -k "{model_type}" -xvs
  2. All convergence tests for the model:
  1. Checkstyle: make checkstyle

Human checkpoint: Report final test results.

Reference Files

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.