transformers - ✅(Solved) Fix Liger Kernel is not applied when creating the model with `model_init` [1 pull requests, 3 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
huggingface/transformers#44315Fetched 2026-04-08 00:29:12
View on GitHub
Comments
3
Participants
2
Timeline
8
Reactions
0
Participants
Timeline (top)
commented ×3closed ×1cross-referenced ×1labeled ×1

Fix Action

Fixed

PR fix notes

PR #44329: Enable Liger Kernel when doing hyperparameter search.

Description (problem / solution / changelog)

What does this PR do?

<!-- Congratulations! You've made it this far! You're not quite done yet though. Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution. Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change. Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost. --> <!-- Remove if not applicable -->

Fixes #44315. Check args.use_liger_kernel after it is updated by _hp_search_setup(trial).

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline, Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the documentation guidelines, and here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@SunMarc

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @ If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**. Please tag fewer than 3 people. Models: - text models: @ArthurZucker @Cyrilvallez - vision models: @yonigozlan @molbap - audio models: @eustlb @ebezzam @vasqu - multimodal models: @zucchini-nlp - graph models: @clefourrier Library: - generate: @zucchini-nlp (visual-language models) or @gante (all others) - continuous batching: @remi-or @ArthurZucker @McPatate - pipelines: @Rocketknight1 - tokenizers: @ArthurZucker and @itazap - trainer: @SunMarc - attention: @vasqu @ArthurZucker @CyrilVallez - model loading (from pretrained, etc): @CyrilVallez - distributed: @3outeille @ArthurZucker - CIs: @ydshieh Integrations: - ray/raytune: @richardliaw, @amogkam - Big Model Inference: @SunMarc - quantization: @SunMarc @MekkCyber - kernels: @MekkCyber @drbh - peft: @BenjaminBossan @githubnemo Devices/Backends: - AMD ROCm: @ivarflakstad - Intel XPU: @IlyasMoutawwakil - Ascend NPU: @ivarflakstad Documentation: @stevhliu Research projects are not maintained and should be taken as is. -->

Changed files

  • src/transformers/trainer.py (modified, +3/-3)
RAW_BUFFERClick to expand / collapse

System Info

N/A

Who can help?

@SunMarc In Trainer.train, the Liger Kernel is not applied when the model is instantiated via call_model_init. As a result, hyperparameter search runs cannot leverage this kernel for acceleration.

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

N/A

Expected behavior

Liger Kernel should be configurable via args.use_liger_kernel when the model is instantiated via model_init.

extent analysis

Fix Plan

Update Model Instantiation to Apply Liger Kernel

To fix the issue, we need to modify the Trainer.train method to apply the Liger Kernel when the model is instantiated via call_model_init. Here are the concrete steps:

Step 1: Update Trainer Class

class Trainer:
    def train(self, args, model_init):
        # Check if Liger Kernel should be used
        if args.use_liger_kernel:
            # Apply Liger Kernel when model is instantiated via `call_model_init`
            if model_init == 'call_model_init':
                model = LigerKernelModel(model_init())
            else:
                model = model_init()
        else:
            model = model_init()

Step 2: Update LigerKernelModel Class

class LigerKernelModel:
    def __init__(self, model):
        self.model = model
        # Initialize Liger Kernel
        self.liger_kernel = LigerKernel()

Step 3: Update LigerKernel Class

class LigerKernel:
    def __init__(self):
        # Initialize Liger Kernel
        pass

    def apply(self, model):
        # Apply Liger Kernel to the model
        pass

Step 4: Update args to Include use_liger_kernel Flag

args = parser.parse_args()
args.use_liger_kernel = True  # Set flag to True to use Liger Kernel

Verification

To verify that the fix worked, run the hyperparameter search with the use_liger_kernel flag set to True. Check if the Liger Kernel is applied correctly and if the hyperparameter search runs with acceleration.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Liger Kernel should be configurable via args.use_liger_kernel when the model is instantiated via model_init.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

transformers - ✅(Solved) Fix Liger Kernel is not applied when creating the model with `model_init` [1 pull requests, 3 comments, 2 participants]