Skip to content

fix: replace HybridCache with Cache in gemma2 and gemma3#1002

Merged
Tcc0403 merged 1 commit intolinkedin:mainfrom
qgallouedec:replace-hybrid-cache
Jan 12, 2026
Merged

fix: replace HybridCache with Cache in gemma2 and gemma3#1002
Tcc0403 merged 1 commit intolinkedin:mainfrom
qgallouedec:replace-hybrid-cache

Conversation

@qgallouedec
Copy link
Copy Markdown
Contributor

HybridCache has been deprecated, and is now removed, see huggingface/transformers#43168, causing

  trl/trainer/dpo_trainer.py:500: in __init__
      super().__init__(
  .venv/lib/python3.12/site-packages/transformers/trainer.py:479: in __init__
      from liger_kernel.transformers import _apply_liger_kernel_to_instance
  .venv/lib/python3.12/site-packages/liger_kernel/transformers/__init__.py:140: in __getattr__
      module = importlib.import_module("liger_kernel.transformers.monkey_patch")
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  /__w/_tool/Python/3.12.12/x64/lib/python3.12/importlib/__init__.py:90: in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  .venv/lib/python3.12/site-packages/liger_kernel/transformers/monkey_patch.py:21: in <module>
      from liger_kernel.transformers.model.gemma2 import lce_forward as gemma2_lce_forward
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  
      import logging
      
      from typing import Optional
      from typing import Tuple
      from typing import Union
      
      import torch
      
      from torch.nn import CrossEntropyLoss
  >   from transformers.cache_utils import HybridCache
  E   ImportError: cannot import name 'HybridCache' from 'transformers.cache_utils' (/__w/trl/trl/.venv/lib/python3.12/site-packages/transformers/cache_utils.py)
  
  .venv/lib/python3.12/site-packages/liger_kernel/transformers/model/gemma2.py:10: ImportError

This PR fixes this issue

Copy link
Copy Markdown
Collaborator

@Tcc0403 Tcc0403 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants