* [modeling][lfm2] LFM2 model on 4.53.0 interface

* [configuration] hook in LFM2 keys

* [modeling][lfm2] update modeling interface for 4.53.1

* [modeling][lfm2] apply mask to hidden conv states

* [misc] ruff format/lint

* [modeling][lfm2] minor: NotImplemented legacy cache conversion

* Create lfm2.md

* create nice modular

* style

* Update modeling_auto.py

* clean and start adding tests

* style

* Update test_modeling_lfm2.py

* Update __init__.py

* small test model size

* config

* small fix

* fix

* remove useless config attrs -> block_dim and conv_dim are hiden_size

* fix prepare inputs

* fix config

* test

* typo

* skip tests accordingly

* config docstrings

* add doc to .md

* skip config docstring check

---------

Co-authored-by: Maxime Labonne <81252890+mlabonne@users.noreply.github.com>
Co-authored-by: Cyril Vallez <cyril.vallez@gmail.com>
This commit is contained in:
Paul Pak
2025-07-10 08:07:33 -06:00
committed by GitHub
parent 38c3931362
commit 9682d07f92
17 changed files with 1645 additions and 6 deletions

View File

@@ -2503,6 +2503,7 @@ class GenerationTesterMixin:
"xlnet",
"zamba",
"zamba2",
"lfm2",
)
has_standard_cache = not any(
model_name in config.__class__.__name__.lower() for model_name in models_without_standard_cache

View File

View File

@@ -0,0 +1,93 @@
# Copyright 2022 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Testing suite for the PyTorch LLaMA model."""
import unittest
from transformers import is_torch_available
from transformers.testing_utils import (
require_read_token,
require_torch,
require_torch_accelerator,
slow,
)
from ...causal_lm_tester import CausalLMModelTest, CausalLMModelTester
if is_torch_available():
from transformers import Lfm2Config, Lfm2ForCausalLM, Lfm2Model
class Lfm2ModelTester(CausalLMModelTester):
if is_torch_available():
config_class = Lfm2Config
base_model_class = Lfm2Model
causal_lm_class = Lfm2ForCausalLM
def __init__(
self,
parent,
layer_types=["full_attention", "conv"],
):
super().__init__(parent)
self.layer_types = layer_types
@require_torch
class Lfm2ModelTest(CausalLMModelTest, unittest.TestCase):
all_model_classes = (Lfm2Model, Lfm2ForCausalLM) if is_torch_available() else ()
pipeline_model_mapping = (
{
"feature-extraction": Lfm2Model,
"text-generation": Lfm2ForCausalLM,
}
if is_torch_available()
else {}
)
test_headmasking = False
test_pruning = False
fx_compatible = False
model_tester_class = Lfm2ModelTester
# used in `test_torch_compile_for_training`
_torch_compile_train_cls = Lfm2ForCausalLM if is_torch_available() else None
@unittest.skip(
"Lfm2 alternates between attention and conv layers, so attention are only returned for attention layers"
)
def test_attention_outputs(self):
pass
@unittest.skip("Lfm2 has a special cache format as it alternates between attention and conv layers")
def test_past_key_values_format(self):
pass
@unittest.skip("Lfm2 has a special cache format which is not compatible with contrastive search")
def test_contrastive_generate(self):
pass
@unittest.skip("Lfm2 has a special cache format which is not compatible with contrastive search")
def test_contrastive_generate_dict_outputs_use_cache(self):
pass
@unittest.skip("Lfm2 has a special cache format which is not compatible with contrastive search")
def test_contrastive_generate_low_memory(self):
pass
@require_torch_accelerator
@require_read_token
@slow
class Lfm2IntegrationTest(unittest.TestCase):
pass