Downloads · 30 days
6
14% of all-time downloads
Rusted-Gold/Florence-2-large-no-flash-attn-Transformers-Fix
Florence-2-large-no-flash-attn-Transformers-Fix is a machine learning model from Rusted-Gold. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This is the Florence-2-large-no-flash-attn model from Microsoft Corporation, made compatible with transformers==4.57.3.
Downloads · 30 days
6
14% of all-time downloads
All-time downloads
44
Public
Repo size
1.5 GB
Likes
0
Public
Click a slice to open those files.
.bin1.5 GB · 99%
From the Hugging Face model README
This is the Florence-2-large-no-flash-attn model from Microsoft Corporation, made compatible with transformers==4.57.3.
Original License: MIT License
Original Copyright: © 2024 Microsoft Corporation
This modified version maintains the original MIT license and respects all original copyright notices. All original code and model weights remain the intellectual property of Microsoft Corporation.
Fixed compatibility issues with transformers==4.57.3 where AttributeError: 'NoneType' object has no attribute 'shape' occurred during model inference and generation.
In transformers 4.57.3, the past_key_values structure can contain None elements at various nesting levels, particularly during early generation stages. The original code only checked for top-level None but not nested None values.
Florence2Attention and Florence2SdpaAttention)modeling_florence2.pypast_key_value[0] is not None check before accessing .shape[2]# Before
if (is_cross_attention and past_key_value is not None
and past_key_value[0].shape[2] == key_value_states.shape[1]):
# After
if (is_cross_attention and past_key_value is not None
and past_key_value[0] is not None
and past_key_value[0].shape[2] == key_value_states.shape[1]):
modeling_florence2.pypast_key_value[0] is not None check before shape access# Before
if past_key_value is not None:
kv_seq_len += past_key_value[0].shape[-2]
# After
if past_key_value is not None and past_key_value[0] is not None:
kv_seq_len += past_key_value[0].shape[-2]
modeling_florence2.pypast_key_values access in try-except blocks with fallbacks# Before
past_length = past_key_values[0][0].shape[2]
# After
try:
past_length = past_key_values[0][0].shape[2]
except (AttributeError, TypeError, IndexError):
past_length = 0
Florence2LearnedPositionalEmbedding.forward near top of modeling_florence2.pypositions = positions + self.offset
if torch.any(positions < 0) or torch.any(positions >= self.num_embeddings):
raise ValueError(...)
return super().forward(positions)
modeling_florence2.py - Multiple locations for robustness✅ Fully backward compatible with older transformers versions
✅ Forward compatible with future transformers versions using DynamicCache
This model variant does not use Flash Attention optimization, making it suitable for:
from transformers import AutoModel, AutoProcessor
import torch
# Load the no-flash-attn model
model = AutoModel.from_pretrained(
"path/to/Florence-2-large-no-flash-attn",
trust_remote_code=True
)
processor = AutoProcessor.from_pretrained(
"path/to/Florence-2-large-no-flash-attn"
)
# Generate with compatibility fixes
model.eval()
with torch.no_grad():
inputs = processor(text="Describe this image", return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=50)
Test the following scenarios to ensure compatibility:
Version: 1.0 (Transformers 4.57.3 Compatible)
Last Updated: March 2026
Status: Production Ready