Skip to content

Commit aa7010f

Browse files
r-barnesfacebook-github-bot
authored andcommitted
Replace hasattr with getattr in aitemplate/AITemplate/python/aitemplate/frontend/nn/multiscale_attention.py (facebookincubator#641)
Summary: Pull Request resolved: facebookincubator#641 The pattern ``` X.Y if hasattr(X, "Y") else Z ``` can be replaced with ``` getattr(X, "Y", Z) ``` The [getattr](https://www.w3schools.com/python/ref_func_getattr.asp) function gives more succinct code than the [hasattr](https://www.w3schools.com/python/ref_func_hasattr.asp) function. Please use it when appropriate. **This diff is very low risk. Green tests indicate that you can safely Accept & Ship.** Differential Revision: D44886430 fbshipit-source-id: 6262fc6d6ae8a3a5dafd9373ab74451b7d20932c
1 parent 32dd05c commit aa7010f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

python/aitemplate/frontend/nn/multiscale_attention.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,17 +428,17 @@ def __init__(
428428
self._attention_pool_q = _AttentionPool(
429429
self.pool_q,
430430
has_cls_embed=self.has_cls_embed,
431-
norm=self.norm_q if hasattr(self, "norm_q") else None,
431+
norm=getattr(self, "norm_q", None),
432432
)
433433
self._attention_pool_k = _AttentionPool(
434434
self.pool_k,
435435
has_cls_embed=self.has_cls_embed,
436-
norm=self.norm_k if hasattr(self, "norm_k") else None,
436+
norm=getattr(self, "norm_k", None),
437437
)
438438
self._attention_pool_v = _AttentionPool(
439439
self.pool_v,
440440
has_cls_embed=self.has_cls_embed,
441-
norm=self.norm_v if hasattr(self, "norm_v") else None,
441+
norm=getattr(self, "norm_v", None),
442442
)
443443

444444
def _qkv_proj(

0 commit comments

Comments
 (0)