Open
Description
Summary
Import style | Search regex | Number of files (links are slightly borked) |
---|---|---|
from torch.nn import functional |
/from torch\.nn import functional$/ |
1.6k |
from torch.nn import functional as <SOMETHING> |
/from torch\.nn import functional as .*$/ |
162k |
from torch.nn import functional as F |
/from torch\.nn import functional as F$/ |
129k |
import torch.nn.functional as <SOMETHING> |
/import torch\.nn\.functional as .*$/ |
1.4M |
import torch.nn.functional as F |
/import torch\.nn\.functional as F$/ |
1.2M |
In total 1.329 / 1.562
~= 85% of the torch.nn.functional
imports are as F
.
Considerations
- Afaict
F
is nowhere explicitly recommended/mentioned by the PyTorch documentation, though it appears in every code example on https://docs.pytorch.org/docs/stable/nn.functional.html
The F
alias violates rule N812, lowercase-imported-as-non-lowercase.
- This is unfortunate, but I think it's case where practicality beats purity, since the
F
alias is so ubiquitous in the PyTorch ecosystem. - I think it's worth making some sort of special case for this in rule N812
- Quick and dirty option: add
functional
to the defaultignore-names
in[tool.ruff.lint.pep8-naming]
- This has the slight disadvantage of allowing all import of
functional
, regardless of whether they are from PyTorch or not, to be importable with uppercase names.
- This has the slight disadvantage of allowing all import of
- Cleaner option: some sort of particular exception for
torch.nn.functional
? Not sure tbh
- Quick and dirty option: add