czczup commited on
Commit
bcc0556
1 Parent(s): b18310a

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. modeling_phi3.py +9 -0
modeling_phi3.py CHANGED
@@ -53,6 +53,7 @@ try:
53
  unpad_input)
54
 
55
  _flash_supports_window_size = 'window_size' in list(inspect.signature(flash_attn_func).parameters)
 
56
  except ImportError as error:
57
  logger.warning(
58
  f'`flash-attention` package not found, consider installing for better performance: {error}.'
@@ -61,6 +62,7 @@ except ImportError as error:
61
  logger.warning(
62
  "Current `flash-attenton` does not support `window_size`. Either upgrade or use `attn_implementation='eager'`."
63
  )
 
64
 
65
  _CHECKPOINT_FOR_DOC = 'microsoft/Phi-3-mini-4k-instruct'
66
  _CONFIG_FOR_DOC = 'Phi3Config'
@@ -937,6 +939,12 @@ class Phi3PreTrainedModel(PreTrainedModel):
937
 
938
  _version = '0.0.5'
939
 
 
 
 
 
 
 
940
  def _init_weights(self, module):
941
  std = self.config.initializer_range
942
  if isinstance(module, nn.Linear):
@@ -1042,6 +1050,7 @@ class Phi3Model(Phi3PreTrainedModel):
1042
  [Phi3DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
1043
  )
1044
  self._attn_implementation = config._attn_implementation
 
1045
  self.norm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
1046
 
1047
  self.gradient_checkpointing = False
 
53
  unpad_input)
54
 
55
  _flash_supports_window_size = 'window_size' in list(inspect.signature(flash_attn_func).parameters)
56
+ has_flash_attn = True
57
  except ImportError as error:
58
  logger.warning(
59
  f'`flash-attention` package not found, consider installing for better performance: {error}.'
 
62
  logger.warning(
63
  "Current `flash-attenton` does not support `window_size`. Either upgrade or use `attn_implementation='eager'`."
64
  )
65
+ has_flash_attn = False
66
 
67
  _CHECKPOINT_FOR_DOC = 'microsoft/Phi-3-mini-4k-instruct'
68
  _CONFIG_FOR_DOC = 'Phi3Config'
 
939
 
940
  _version = '0.0.5'
941
 
942
+ def __init__(self, config: Phi3Config):
943
+ if not has_flash_attn:
944
+ config._attn_implementation = 'eager'
945
+ print('Warning: Flash attention is not available, using eager attention instead.')
946
+ super().__init__(config)
947
+
948
  def _init_weights(self, module):
949
  std = self.config.initializer_range
950
  if isinstance(module, nn.Linear):
 
1050
  [Phi3DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
1051
  )
1052
  self._attn_implementation = config._attn_implementation
1053
+
1054
  self.norm = Phi3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
1055
 
1056
  self.gradient_checkpointing = False