-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Use dict instead of OrderedDict in maxvit #6927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import math | ||
from functools import partial | ||
from typing import Any, Callable, List, Optional, OrderedDict, Sequence, Tuple | ||
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple | ||
|
||
import numpy as np | ||
import torch | ||
|
@@ -96,7 +96,7 @@ def __init__( | |
else: | ||
self.stochastic_depth = nn.Identity() # type: ignore | ||
|
||
_layers = OrderedDict() | ||
_layers = {} | ||
_layers["pre_norm"] = norm_layer(in_channels) | ||
_layers["conv_a"] = Conv2dNormActivation( | ||
in_channels, | ||
|
@@ -426,7 +426,7 @@ def __init__( | |
) -> None: | ||
super().__init__() | ||
|
||
layers: OrderedDict[str, Any] = OrderedDict() # type: ignore | ||
layers: Dict[str, Any] = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This dictionary was intended to maintain the order of layers so that the sequential call at like 469 will execute them in the right order. Edit: think the order might be maintained for low number of keys but this is a not-guaranteed behaviour and might be different from platform to platform. I recommend restoring the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @datumbox all dicts preserve insertion order as of Python 3.6: https://stackoverflow.com/questions/39980323/are-dictionaries-ordered-in-python-3-6. EDIT: more importantly it is also a guaranteed language feature from 3.7, so it's not just a CPython detail. I was assuming this would fulfil the requirements you noted for the sequential call. Am I missing something important? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PyTorch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, it's not an implementation detail anymore in 3.7. It's a guaranteed language feature (see link above). We can rely on it. As noted below There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes dicts are insertion ordered from python 3.7. This is legit feature and used widely. |
||
|
||
# convolutional layer | ||
layers["MBconv"] = MBConv( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, by removing the order the
Sequential
won't work as we expect.