Fix AttributeError: Florence2LanguageConfig has no attribute forced_bos_token_id

#121
configuration_florence2.py CHANGED
@@ -261,6 +261,7 @@ class Florence2LanguageConfig(PretrainedConfig):
261
  **kwargs,
262
  )
263
 
 
264
  # ensure backward compatibility for BART CNN models
265
  if self.forced_bos_token_id is None and kwargs.get("force_bos_token_to_be_generated", False):
266
  self.forced_bos_token_id = self.bos_token_id
 
261
  **kwargs,
262
  )
263
 
264
+ self.forced_bos_token_id = kwargs.get("forced_bos_token_id", None)
265
  # ensure backward compatibility for BART CNN models
266
  if self.forced_bos_token_id is None and kwargs.get("force_bos_token_to_be_generated", False):
267
  self.forced_bos_token_id = self.bos_token_id
processing_florence2.py CHANGED
@@ -86,7 +86,9 @@ class Florence2Processor(ProcessorMixin):
86
 
87
  tokens_to_add = {
88
  'additional_special_tokens': \
89
- tokenizer.additional_special_tokens + \
 
 
90
  ['<od>', '</od>', '<ocr>', '</ocr>'] + \
91
  [f'<loc_{x}>' for x in range(1000)] + \
92
  ['<cap>', '</cap>', '<ncap>', '</ncap>','<dcap>', '</dcap>', '<grounding>', '</grounding>', '<seg>', '</seg>', '<sep>', '<region_cap>', '</region_cap>', '<region_to_desciption>', '</region_to_desciption>', '<proposal>', '</proposal>', '<poly>', '</poly>', '<and>']
 
86
 
87
  tokens_to_add = {
88
  'additional_special_tokens': \
89
+ (getattr(tokenizer, "extra_special_tokens", None)
90
+ if getattr(tokenizer, "extra_special_tokens", None) is not None
91
+ else getattr(tokenizer, "additional_special_tokens", [])) + \
92
  ['<od>', '</od>', '<ocr>', '</ocr>'] + \
93
  [f'<loc_{x}>' for x in range(1000)] + \
94
  ['<cap>', '</cap>', '<ncap>', '</ncap>','<dcap>', '</dcap>', '<grounding>', '</grounding>', '<seg>', '</seg>', '<sep>', '<region_cap>', '</region_cap>', '<region_to_desciption>', '</region_to_desciption>', '<proposal>', '</proposal>', '<poly>', '</poly>', '<and>']