Skip to content

Commit

Permalink
Fix natten (huggingface#22229)
Browse files Browse the repository at this point in the history
* Add kernel size to NATTEN's QK arguments.

The new NATTEN 0.14.5 supports PyTorch 2.0, but also adds an additional
argument to the QK operation to allow optional RPBs.

This ends up failing NATTEN tests.

This commit adds NATTEN back to circleci and adds the arguments to get
it working again.

* Force NATTEN >= 0.14.5
  • Loading branch information
alihassanijr authored and raghavanone committed Apr 5, 2023
1 parent b923c05 commit 52e69dd
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 6 deletions.
3 changes: 1 addition & 2 deletions .circleci/create_circleci_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,7 @@ def job_name(self):
"pip install 'git+https://github.com/facebookresearch/detectron2.git'",
"sudo apt install tesseract-ocr",
"pip install pytesseract",
# wait until natten is ready for torch 2.0.0
# "pip install natten",
"pip install natten",
],
tests_to_run=[
"tests/models/*layoutlmv*",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"keras-nlp>=0.3.1",
"librosa",
"nltk",
"natten>=0.14.4",
"natten>=0.14.5",
"numpy>=1.17",
"onnxconverter-common",
"onnxruntime-tools>=1.4.2",
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/dependency_versions_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"keras-nlp": "keras-nlp>=0.3.1",
"librosa": "librosa",
"nltk": "nltk",
"natten": "natten>=0.14.4",
"natten": "natten>=0.14.5",
"numpy": "numpy>=1.17",
"onnxconverter-common": "onnxconverter-common",
"onnxruntime-tools": "onnxruntime-tools>=1.4.2",
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/models/dinat/modeling_dinat.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def forward(
query_layer = query_layer / math.sqrt(self.attention_head_size)

# Compute NA between "query" and "key" to get the raw attention scores, and add relative positional biases.
attention_scores = natten2dqkrpb(query_layer, key_layer, self.rpb, self.dilation)
attention_scores = natten2dqkrpb(query_layer, key_layer, self.rpb, self.kernel_size, self.dilation)

# Normalize the attention scores to probabilities.
attention_probs = nn.functional.softmax(attention_scores, dim=-1)
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/models/nat/modeling_nat.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def forward(
query_layer = query_layer / math.sqrt(self.attention_head_size)

# Compute NA between "query" and "key" to get the raw attention scores, and add relative positional biases.
attention_scores = natten2dqkrpb(query_layer, key_layer, self.rpb, 1)
attention_scores = natten2dqkrpb(query_layer, key_layer, self.rpb, self.kernel_size, 1)

# Normalize the attention scores to probabilities.
attention_probs = nn.functional.softmax(attention_scores, dim=-1)
Expand Down

0 comments on commit 52e69dd

Please sign in to comment.