mjkmain commited on
Commit
f613c3a
·
verified ·
1 Parent(s): 75e790d

Update _modeling_kormo.py

Browse files
Files changed (1) hide show
  1. _modeling_kormo.py +6 -15
_modeling_kormo.py CHANGED
@@ -94,13 +94,13 @@ def rotate_half(x):
94
  x1 = x[..., : x.shape[-1] // 2]
95
  x2 = x[..., x.shape[-1] // 2 :]
96
  return torch.cat((-x2, x1), dim=-1)
97
-
98
  def copy_(tensor: torch.Tensor, other: torch.Tensor) -> torch.Tensor:
99
  if not getattr(tensor, "_is_hf_initialized", False):
100
  with torch.no_grad():
101
  return tensor.copy_(other)
102
  return tensor
103
-
104
  class Attention(nn.Module):
105
  """Multi-headed attention from 'Attention Is All You Need' paper"""
106
 
@@ -261,7 +261,7 @@ class RotaryEmbedding(nn.Module):
261
  base ** (torch.arange(0, dim, 2, dtype=torch.int64).to(device=device, dtype=torch.float) / dim)
262
  )
263
  return inv_freq, attention_factor
264
-
265
  @torch.no_grad()
266
  @dynamic_rope_update # power user: used with advanced RoPE types (e.g. dynamic rope)
267
  def forward(self, x, position_ids):
@@ -277,10 +277,6 @@ class RotaryEmbedding(nn.Module):
277
  return cos, sin
278
 
279
 
280
-
281
-
282
-
283
-
284
  class KORMoPreTrainedModel(PreTrainedModel):
285
  config_class = KORMoConfig
286
  base_model_prefix = "model"
@@ -316,8 +312,7 @@ class KORMoPreTrainedModel(PreTrainedModel):
316
  )
317
  buffer_value, _ = rope_fn(module.config)
318
  copy_(module.inv_freq, buffer_value)
319
- copy_(module.original_inv_freq, buffer_value)
320
-
321
 
322
  class KORMoModel(KORMoPreTrainedModel):
323
  def __init__(self, config: KORMoConfig):
@@ -390,14 +385,12 @@ class KORMoModel(KORMoPreTrainedModel):
390
  position_ids = cache_position.unsqueeze(0)
391
 
392
  if self.config._attn_implementation == "flash_attention_3_doc":
393
- ### TODO: 수정필요
394
  causal_mask = attention_mask
395
  else:
396
  causal_mask = create_causal_mask(
397
  config=self.config,
398
- input_embeds=inputs_embeds,
399
  attention_mask=attention_mask,
400
- cache_position=cache_position,
401
  past_key_values=past_key_values,
402
  position_ids=position_ids,
403
  )
@@ -525,6 +518,4 @@ class KORMoForCausalLM(KORMoPreTrainedModel, GenerationMixin):
525
  past_key_values=outputs.past_key_values,
526
  hidden_states=outputs.hidden_states,
527
  attentions=outputs.attentions,
528
- )
529
-
530
-
 
94
  x1 = x[..., : x.shape[-1] // 2]
95
  x2 = x[..., x.shape[-1] // 2 :]
96
  return torch.cat((-x2, x1), dim=-1)
97
+
98
  def copy_(tensor: torch.Tensor, other: torch.Tensor) -> torch.Tensor:
99
  if not getattr(tensor, "_is_hf_initialized", False):
100
  with torch.no_grad():
101
  return tensor.copy_(other)
102
  return tensor
103
+
104
  class Attention(nn.Module):
105
  """Multi-headed attention from 'Attention Is All You Need' paper"""
106
 
 
261
  base ** (torch.arange(0, dim, 2, dtype=torch.int64).to(device=device, dtype=torch.float) / dim)
262
  )
263
  return inv_freq, attention_factor
264
+
265
  @torch.no_grad()
266
  @dynamic_rope_update # power user: used with advanced RoPE types (e.g. dynamic rope)
267
  def forward(self, x, position_ids):
 
277
  return cos, sin
278
 
279
 
 
 
 
 
280
  class KORMoPreTrainedModel(PreTrainedModel):
281
  config_class = KORMoConfig
282
  base_model_prefix = "model"
 
312
  )
313
  buffer_value, _ = rope_fn(module.config)
314
  copy_(module.inv_freq, buffer_value)
315
+ copy_(module.original_inv_freq, buffer_value)
 
316
 
317
  class KORMoModel(KORMoPreTrainedModel):
318
  def __init__(self, config: KORMoConfig):
 
385
  position_ids = cache_position.unsqueeze(0)
386
 
387
  if self.config._attn_implementation == "flash_attention_3_doc":
 
388
  causal_mask = attention_mask
389
  else:
390
  causal_mask = create_causal_mask(
391
  config=self.config,
392
+ inputs_embeds=inputs_embeds,
393
  attention_mask=attention_mask,
 
394
  past_key_values=past_key_values,
395
  position_ids=position_ids,
396
  )
 
518
  past_key_values=outputs.past_key_values,
519
  hidden_states=outputs.hidden_states,
520
  attentions=outputs.attentions,
521
+ )