liger-autopatch
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).
适合你,如果你需要为 Transformers 模型快速添加 Liger Kernel 支持
npx oh-my-skill add linkedin/liger-kernel/liger-autopatchcurl -fsSL https://oh-my-skill.com/install.sh | bash -s -- linkedin/liger-kernel/liger-autopatchnpx oh-my-skill verify linkedin/liger-kernel/liger-autopatch怎么用
商店整理自技能原文 · 版本 e9bbef0 · 表述以原文为准安装后,如果你要求添加或修改Liger Kernel对HuggingFace模型的支持,Claude会自动分析模型代码、生成补丁文件、运行测试,并在每个阶段请你确认。
当你要求为Liger Kernel添加一个新模型的支持,或者更新、修复、扩展现有的模型补丁时触发。关键词如“添加”、“更新”、“修复”等。
技能原文 SKILL.md
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
- Create mode: User asks to add/patch/support a new model → full pipeline (Analyze → Generate → Validate)
- Modify mode: User asks to update/fix/change/extend an existing monkey-patch → lighter pipeline (Change Impact Analysis → Apply Changes → Validate)
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](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](decision-matrix.md).
Human checkpoint: Present the profile. Confirm before proceeding.
Stage 2: Generate
Follow the Code Generator workflow in [code-generator.md](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— MODIFY
Human checkpoint: Present changes for review.
Stage 3: Validate
Follow the Validator workflow in [validator.md](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:
- What is being added/changed/fixed
- Which Liger kernel(s) are involved
- Which files need modification (subset of the 13 files from create mode)
- What the expected behavior should be after the change
Human checkpoint: Present the change plan. Confirm before proceeding.
Stage 2: Apply Changes
Follow the Code Generator workflow in [code-generator.md](code-generator.md) in modify mode.
Human checkpoint: Present changes for review.
Stage 3: Validate
Follow the Validator workflow in [validator.md](validator.md). This stage is mandatory — do not skip it. At minimum, run:
- Instance patching test:
pytest test/transformers/test_monkey_patch.py -k "{model_type}" -xvs - All convergence tests for the model:
pytest 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)- If VL (multimodal) model, also run:
pytest test/convergence/bf16/test_mini_models_multimodal.py -k "{model_type}" -xvspytest test/convergence/fp32/test_mini_models_multimodal.py -k "{model_type}" -xvs- Checkstyle:
make checkstyle
Human checkpoint: Report final test results.
Reference Files
- [decision-matrix.md](decision-matrix.md) — 12 architectural decisions to resolve per model
- [examples/llama-profile.md](examples/llama-profile.md) — Reference profile for standard dense model
- [examples/gemma-profile.md](examples/gemma-profile.md) — Reference profile showing GeGLU + offset variant
- Templates in [templates/](templates/) — Code generation patterns for each file type