-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b6cc797
commit f26c79e
Showing
15 changed files
with
105 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,3 +54,4 @@ You are now ready to build the doc (here in html):: | |
make html | ||
|
||
The results will be in `_build/html` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,3 +65,70 @@ def _process_decomposition(self): | |
|
||
return decomposition | ||
|
||
|
||
class ParameterList(nn.Module): | ||
def __init__(self, parameters=None): | ||
super().__init__() | ||
self.keys = [] | ||
self.counter = 0 | ||
if parameters is not None: | ||
self.extend(parameters) | ||
|
||
def _unique_key(self): | ||
"""Creates a new unique key""" | ||
key = f'param_{self.counter}' | ||
self.counter += 1 | ||
return key | ||
|
||
def append(self, element): | ||
# p = nn.Parameter(element) | ||
key = self._unique_key() | ||
self.register_parameter(key, element) | ||
self.keys.append(key) | ||
|
||
def insert(self, index, element): | ||
# p = nn.Parameter(element) | ||
key = self._unique_key() | ||
self.register_parameter(key, element) | ||
self.keys.insert(index, key) | ||
|
||
def pop(self, index=-1): | ||
item = self[index] | ||
self.__delitem__(index) | ||
return item | ||
|
||
def __getitem__(self, index): | ||
keys = self.keys[index] | ||
if isinstance(keys, list): | ||
#return self.__class__([getattr(self, key) for key in keys]) | ||
params = [getattr(self, key) for key in keys] | ||
return self.__class__(params) | ||
return getattr(self, keys) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
JeanKossaifi
Author
Member
|
||
|
||
def __setitem__(self, index, value): | ||
self.register_parameter(self.keys[index], value) | ||
|
||
def __delitem__(self, index): | ||
delattr(self, self.keys[index]) | ||
self.keys.__delitem__(index) | ||
|
||
def __len__(self): | ||
return len(self.keys) | ||
|
||
def extend(self, parameters): | ||
for param in parameters: | ||
self.append(param) | ||
|
||
def __iadd__(self, parameters): | ||
return self.extend(parameters) | ||
|
||
def extra_repr(self) -> str: | ||
child_lines = [] | ||
for k, p in self._parameters.items(): | ||
size_str = 'x'.join(str(size) for size in p.size()) | ||
device_str = '' if not p.is_cuda else ' (GPU {})'.format(p.get_device()) | ||
parastr = 'Parameter containing: [{} of size {}{}]'.format( | ||
torch.typename(p), size_str, device_str) | ||
child_lines.append(' (' + str(k) + '): ' + parastr) | ||
tmpstr = '\n'.join(child_lines) | ||
return tmpstr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How does this solve the issue with DataParallel?