590 qk_scale: Optional[float] = None,
591 drop: float = 0.,
592 attn_drop: float = 0.,
593 drop_path: float = 0., 594 act_layer: Optional[nn.Module] = nn.GELU,
595 norm_layer: Optional[nn.Module] = nn.LayerNorm
596 ):
494 qk_scale: Optional[float] = None,
495 drop: float = 0.,
496 attn_drop: float = 0.,
497 drop_path: Union[float, tuple[float, ...]] = 0., 498 norm_layer: Optional[nn.Module] = nn.LayerNorm,
499 downsample: Optional[nn.Module] = None,
500 use_checkpoint: bool = False,
403 qk_scale: Optional[float] = None,
404 drop: float = 0.,
405 attn_drop: float = 0.,
406 drop_path: Union[float, tuple[float, ...]] = 0., 407 norm_layer: Optional[nn.Module] = nn.LayerNorm,
408 downsample: Optional[nn.Module] = None,
409 use_checkpoint: bool = False
593 qk_scale: Optional[float] = None,
594 drop: float = 0.,
595 attn_drop: float = 0.,
596 drop_path: float = 0., 597 act_layer: Optional[nn.Module] = nn.GELU,
598 norm_layer: Optional[nn.Module] = nn.LayerNorm
599 ):
487 qk_scale: Optional[float] = None,
488 drop: float = 0.,
489 attn_drop: float = 0.,
490 drop_path: float = 0., 491 norm_layer: Optional[nn.Module] = nn.LayerNorm,
492 downsample: Optional[nn.Module] = None,
493 use_checkpoint: bool = False
The local variable name hides the variable defined in the outer scope, making it inaccessible and might confuse.
filename = 'myfile.txt'
def read_file(filename): # This shadows the global `filename`
with open(filename) as file:
return file.readlines()
FILENAME = 'myfile.txt' # renamed global to UPPER_CASE as convention
def read_file(filename):
with open(filename) as file:
return file.readlines()
Another usual suspect of this is when you use the same parameter name inside a function as the global variable you are using. For example:
def run_app(app):
# This `app` shadows the global app...
app.run()
if __name__ == '__main__':
app = MyApp() # This is a global variable!
run_app(app)
To avoid this re-defining of a global, consider not defining app
as a global, but inside a main()
function instead:
def run_app(app):
# There is no longer a global `app` variable.
app.run()
def main():
app = MyApp()
run_app(app)
if __name__ == '__main__':
main()