Spaces:
Running on Zero
Running on Zero
transformers 5 compat
Browse files- models/bagel/qwen2/modeling_qwen2.py +15 -1
- requirements.txt +1 -1
models/bagel/qwen2/modeling_qwen2.py
CHANGED
|
@@ -17,6 +17,20 @@ from transformers.modeling_outputs import (
|
|
| 17 |
CausalLMOutputWithPast,
|
| 18 |
)
|
| 19 |
from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
from transformers.modeling_utils import PreTrainedModel
|
| 21 |
from transformers.utils import (
|
| 22 |
add_start_docstrings,
|
|
@@ -103,7 +117,7 @@ class Qwen2RotaryEmbedding(nn.Module):
|
|
| 103 |
self.original_max_seq_len = config.max_position_embeddings
|
| 104 |
|
| 105 |
self.config = config
|
| 106 |
-
self.rope_init_fn = ROPE_INIT_FUNCTIONS
|
| 107 |
|
| 108 |
inv_freq, self.attention_scaling = self.rope_init_fn(
|
| 109 |
self.config, device, **self.rope_kwargs
|
|
|
|
| 17 |
CausalLMOutputWithPast,
|
| 18 |
)
|
| 19 |
from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _default_rope_init(config, device=None, seq_len=None, **rope_kwargs):
|
| 23 |
+
# transformers>=5 dropped the "default" entry from ROPE_INIT_FUNCTIONS; this is the v4 implementation.
|
| 24 |
+
if len(rope_kwargs) > 0:
|
| 25 |
+
base = rope_kwargs["base"]
|
| 26 |
+
dim = rope_kwargs["dim"]
|
| 27 |
+
else:
|
| 28 |
+
base = config.rope_theta
|
| 29 |
+
partial_rotary_factor = getattr(config, "partial_rotary_factor", 1.0)
|
| 30 |
+
head_dim = getattr(config, "head_dim", None) or config.hidden_size // config.num_attention_heads
|
| 31 |
+
dim = int(head_dim * partial_rotary_factor)
|
| 32 |
+
inv_freq = 1.0 / (base ** (torch.arange(0, dim, 2, dtype=torch.int64).float().to(device) / dim))
|
| 33 |
+
return inv_freq, 1.0
|
| 34 |
from transformers.modeling_utils import PreTrainedModel
|
| 35 |
from transformers.utils import (
|
| 36 |
add_start_docstrings,
|
|
|
|
| 117 |
self.original_max_seq_len = config.max_position_embeddings
|
| 118 |
|
| 119 |
self.config = config
|
| 120 |
+
self.rope_init_fn = ROPE_INIT_FUNCTIONS.get(self.rope_type, _default_rope_init)
|
| 121 |
|
| 122 |
inv_freq, self.attention_scaling = self.rope_init_fn(
|
| 123 |
self.config, device, **self.rope_kwargs
|
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
torch==2.8.0
|
| 2 |
torchvision==0.23.0
|
| 3 |
-
transformers==
|
| 4 |
accelerate
|
| 5 |
safetensors
|
| 6 |
einops
|
|
|
|
| 1 |
torch==2.8.0
|
| 2 |
torchvision==0.23.0
|
| 3 |
+
transformers==5.24.1
|
| 4 |
accelerate
|
| 5 |
safetensors
|
| 6 |
einops
|