From fd2f17a7a1197529474c24551f1f1d8f534168a3 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sat, 21 Dec 2019 18:07:03 +0100 Subject: [PATCH] Fix E714 flake8 warning (x8). --- examples/summarization/modeling_bertabs.py | 2 +- templates/adding_a_new_model/modeling_tf_xxx.py | 2 +- transformers/modeling_tf_albert.py | 2 +- transformers/modeling_tf_bert.py | 2 +- transformers/modeling_tf_gpt2.py | 2 +- transformers/modeling_tf_openai.py | 2 +- transformers/modeling_tf_t5.py | 2 +- transformers/modeling_tf_transfo_xl.py | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/summarization/modeling_bertabs.py b/examples/summarization/modeling_bertabs.py index e8087f3001..22e50b5e78 100644 --- a/examples/summarization/modeling_bertabs.py +++ b/examples/summarization/modeling_bertabs.py @@ -519,7 +519,7 @@ class MultiHeadedAttention(nn.Module): attn = self.softmax(scores) - if not predefined_graph_1 is None: + if predefined_graph_1 is not None: attn_masked = attn[:, -1] * predefined_graph_1 attn_masked = attn_masked / (torch.sum(attn_masked, 2).unsqueeze(2) + 1e-9) diff --git a/templates/adding_a_new_model/modeling_tf_xxx.py b/templates/adding_a_new_model/modeling_tf_xxx.py index 6478264ffe..7b576a65dc 100644 --- a/templates/adding_a_new_model/modeling_tf_xxx.py +++ b/templates/adding_a_new_model/modeling_tf_xxx.py @@ -152,7 +152,7 @@ class TFXxxMainLayer(tf.keras.layers.Layer): # attention_probs has shape bsz x n_heads x N x N # input head_mask has shape [num_heads] or [num_hidden_layers x num_heads] # and head_mask is converted to shape [num_hidden_layers x batch x num_heads x seq_length x seq_length] - if not head_mask is None: + if head_mask is not None: raise NotImplementedError else: head_mask = [None] * self.num_hidden_layers diff --git a/transformers/modeling_tf_albert.py b/transformers/modeling_tf_albert.py index e921dc8caa..7cc4621437 100644 --- a/transformers/modeling_tf_albert.py +++ b/transformers/modeling_tf_albert.py @@ -686,7 +686,7 @@ class TFAlbertModel(TFAlbertPreTrainedModel): # attention_probs has shape bsz x n_heads x N x N # input head_mask has shape [num_heads] or [num_hidden_layers x num_heads] # and head_mask is converted to shape [num_hidden_layers x batch x num_heads x seq_length x seq_length] - if not head_mask is None: + if head_mask is not None: raise NotImplementedError else: head_mask = [None] * self.num_hidden_layers diff --git a/transformers/modeling_tf_bert.py b/transformers/modeling_tf_bert.py index 4f919eab2d..1360b1951c 100644 --- a/transformers/modeling_tf_bert.py +++ b/transformers/modeling_tf_bert.py @@ -562,7 +562,7 @@ class TFBertMainLayer(tf.keras.layers.Layer): # attention_probs has shape bsz x n_heads x N x N # input head_mask has shape [num_heads] or [num_hidden_layers x num_heads] # and head_mask is converted to shape [num_hidden_layers x batch x num_heads x seq_length x seq_length] - if not head_mask is None: + if head_mask is not None: raise NotImplementedError else: head_mask = [None] * self.num_hidden_layers diff --git a/transformers/modeling_tf_gpt2.py b/transformers/modeling_tf_gpt2.py index 9ad049e9c2..85f9773e07 100644 --- a/transformers/modeling_tf_gpt2.py +++ b/transformers/modeling_tf_gpt2.py @@ -311,7 +311,7 @@ class TFGPT2MainLayer(tf.keras.layers.Layer): # attention_probs has shape bsz x n_heads x N x N # input head_mask has shape [num_heads] or [num_hidden_layers x num_heads] # and head_mask is converted to shape [num_hidden_layers x batch x num_heads x seq_length x seq_length] - if not head_mask is None: + if head_mask is not None: raise NotImplementedError else: head_mask = [None] * self.num_hidden_layers diff --git a/transformers/modeling_tf_openai.py b/transformers/modeling_tf_openai.py index 1fd2e961f2..f7f98ecfd3 100644 --- a/transformers/modeling_tf_openai.py +++ b/transformers/modeling_tf_openai.py @@ -303,7 +303,7 @@ class TFOpenAIGPTMainLayer(tf.keras.layers.Layer): # attention_probs has shape bsz x n_heads x N x N # input head_mask has shape [num_heads] or [num_hidden_layers x num_heads] # and head_mask is converted to shape [num_hidden_layers x batch x num_heads x seq_length x seq_length] - if not head_mask is None: + if head_mask is not None: raise NotImplementedError else: head_mask = [None] * self.num_hidden_layers diff --git a/transformers/modeling_tf_t5.py b/transformers/modeling_tf_t5.py index 5ab16ea433..84767eb13d 100644 --- a/transformers/modeling_tf_t5.py +++ b/transformers/modeling_tf_t5.py @@ -456,7 +456,7 @@ class TFT5MainLayer(tf.keras.layers.Layer): # attention_probs has shape bsz x n_heads x N x N # input head_mask has shape [num_heads] or [num_hidden_layers x num_heads] # and head_mask is converted to shape [num_hidden_layers x batch x num_heads x seq_length x seq_length] - if not head_mask is None: + if head_mask is not None: raise NotImplementedError else: head_mask = [None] * self.num_hidden_layers diff --git a/transformers/modeling_tf_transfo_xl.py b/transformers/modeling_tf_transfo_xl.py index b6807d33dd..b5618df38a 100644 --- a/transformers/modeling_tf_transfo_xl.py +++ b/transformers/modeling_tf_transfo_xl.py @@ -554,7 +554,7 @@ class TFTransfoXLMainLayer(tf.keras.layers.Layer): # attention_probs has shape bsz x n_heads x N x N # input head_mask has shape [num_heads] or [num_hidden_layers x num_heads] (a head_mask for each layer) # and head_mask is converted to shape [num_hidden_layers x qlen x klen x bsz x n_head] - if not head_mask is None: + if head_mask is not None: raise NotImplementedError else: head_mask = [None] * self.n_layer