@@ -692,7 +692,9 @@ def create_causal_mask(
692692 useful to easily overlay another mask on top of the causal one, for example for image tokens handling.
693693 """
694694 # If we have an HybridCache structure, here we want to create the mask for the full layers
695- is_sliding = [getattr (layer , "is_sliding" , False ) for layer in past_key_values .layers ]
695+ is_sliding = []
696+ if past_key_values is not None :
697+ is_sliding = [getattr (layer , "is_sliding" , False ) for layer in past_key_values .layers ]
696698 layer_idx = is_sliding .index (True ) if True in is_sliding else 0
697699
698700 early_exit , attention_mask , kv_length , kv_offset = _preprocess_mask_arguments (
@@ -772,7 +774,9 @@ def create_sliding_window_causal_mask(
772774 useful to easily overlay another mask on top of the sliding causal one, for example for image tokens handling.
773775 """
774776 # If we have an HybridCache structure, here we want to create the mask for the sliding layers
775- is_sliding = [getattr (layer , "is_sliding" , False ) for layer in past_key_values .layers ]
777+ is_sliding = []
778+ if past_key_values is not None :
779+ is_sliding = [getattr (layer , "is_sliding" , False ) for layer in past_key_values .layers ]
776780 layer_idx = is_sliding .index (True ) if True in is_sliding else 0
777781
778782 early_exit , attention_mask , kv_length , kv_offset = _preprocess_mask_arguments (
@@ -857,7 +861,9 @@ def create_chunked_causal_mask(
857861 useful to easily overlay another mask on top of the chunked causal one, for example for image tokens handling.
858862 """
859863 # If we have an HybridCache structure, here we want to create the mask for the sliding layers
860- is_sliding = [getattr (layer , "is_sliding" , False ) for layer in past_key_values .layers ]
864+ is_sliding = []
865+ if past_key_values is not None :
866+ is_sliding = [getattr (layer , "is_sliding" , False ) for layer in past_key_values .layers ]
861867 layer_idx = is_sliding .index (True ) if True in is_sliding else 0
862868
863869 early_exit , attention_mask , kv_length , kv_offset = _preprocess_mask_arguments (
0 commit comments