From 4b2ca9b030eb05668df883c74e50b95dc22176e3 Mon Sep 17 00:00:00 2001 From: Pedro Cuenca Date: Tue, 11 Jul 2023 20:21:05 +0200 Subject: [PATCH] gpt-bigcode: avoid `zeros_` to support Core ML. In-place `zeros_` is not supported by the Core ML conversion process. This PR replaces it with `zeros_like` so conversion can proceed. The change only affects a workaround for a PyTorch bug on the `cpu` device. --- src/transformers/models/gpt_bigcode/modeling_gpt_bigcode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transformers/models/gpt_bigcode/modeling_gpt_bigcode.py b/src/transformers/models/gpt_bigcode/modeling_gpt_bigcode.py index a45b9bd4b26..8c93e583f88 100644 --- a/src/transformers/models/gpt_bigcode/modeling_gpt_bigcode.py +++ b/src/transformers/models/gpt_bigcode/modeling_gpt_bigcode.py @@ -164,7 +164,7 @@ def _attn(self, query, key, value, attention_mask=None, head_mask=None): # This is needed because of a bug in pytorch https://github.com/pytorch/pytorch/issues/80588. # The bug was fixed in https://github.com/pytorch/pytorch/pull/96086, # but the fix has not been released as of pytorch version 2.0.0. - attn_weights.zero_() + attn_weights = torch.zeros_like(attn_weights) beta = 1 else: beta = 0