rockerBOO commited on
Commit
3502d39
·
verified ·
1 Parent(s): bb44b80

Add GenerationMixin to ConditionalGeneration class

Browse files

Florence2LanguageForConditionalGeneration has generative capabilities, as `prepare_inputs_for_generation` is explicitly overwritten. However, it doesn't directly inherit from `GenerationMixin`. From 👉v4.50👈 onwards, `PreTrainedModel` will NOT inherit from `GenerationMixin`, and this model will lose the ability to call `generate` and other related functions.
- If you're using `trust_remote_code=True`, you can get rid of this warning by loading the model with an auto class. See https://huggingface.co/docs/transformers/en/model_doc/auto#auto-classes
- If you are the owner of the model architecture code, please modify your model class such that it inherits from `GenerationMixin` (after `PreTrainedModel`, otherwise you'll get an exception).
- If you are not the owner of the model architecture class, please contact the model code owner to update it.

Files changed (1) hide show
  1. modeling_florence2.py +2 -1
modeling_florence2.py CHANGED
@@ -28,6 +28,7 @@ from collections import OrderedDict
28
  from einops import rearrange
29
  from timm.models.layers import DropPath, trunc_normal_
30
 
 
31
  from transformers.modeling_utils import PreTrainedModel
32
  from transformers.utils import (
33
  ModelOutput,
@@ -2529,7 +2530,7 @@ class Florence2VisionModelWithProjection(Florence2PreTrainedModel):
2529
  """The FLORENCE2 model which consists of a vision backbone and a language model.""",
2530
  FLORENCE2_START_DOCSTRING,
2531
  )
2532
- class Florence2ForConditionalGeneration(Florence2PreTrainedModel):
2533
  def __init__(self, config: Florence2Config):
2534
  super().__init__(config)
2535
  assert config.vision_config.model_type == 'davit', 'only DaViT is supported for now'
 
28
  from einops import rearrange
29
  from timm.models.layers import DropPath, trunc_normal_
30
 
31
+ from transformers import GenerationMixin
32
  from transformers.modeling_utils import PreTrainedModel
33
  from transformers.utils import (
34
  ModelOutput,
 
2530
  """The FLORENCE2 model which consists of a vision backbone and a language model.""",
2531
  FLORENCE2_START_DOCSTRING,
2532
  )
2533
+ class Florence2ForConditionalGeneration(Florence2PreTrainedModel, GenerationMixin):
2534
  def __init__(self, config: Florence2Config):
2535
  super().__init__(config)
2536
  assert config.vision_config.model_type == 'davit', 'only DaViT is supported for now'