-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
4 changed files
with
29 additions
and
55 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
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 |
---|---|---|
@@ -1,30 +1,25 @@ | ||
from torch.nn import Linear, Module | ||
import pytest | ||
|
||
from lighter.utils.patches import PatchedModuleDict | ||
|
||
|
||
def test_patched_module_dict_handles_reserved_names(): | ||
# Test with previously problematic reserved names | ||
reserved_names = { | ||
'type': None, | ||
'to': None, | ||
'forward': Linear(10, 10), | ||
'training': Linear(10, 10), | ||
'modules': [Linear(10, 10)] | ||
"type": None, | ||
"to": None, | ||
"forward": Linear(10, 10), | ||
"training": Linear(10, 10), | ||
} | ||
|
||
# Should work without raising exceptions | ||
patched_dict = PatchedModuleDict(reserved_names) | ||
|
||
# Verify all keys are accessible | ||
for key in reserved_names: | ||
assert key in patched_dict | ||
assert isinstance(patched_dict[key], Linear) | ||
|
||
# Test dictionary operations | ||
assert set(patched_dict.keys()) == set(reserved_names.keys()) | ||
assert len(patched_dict.values()) == len(reserved_names) | ||
|
||
assert patched_dict[key] == reserved_names[key] | ||
|
||
# Test deletion | ||
del patched_dict['type'] | ||
assert 'type' not in patched_dict | ||
del patched_dict["type"] | ||
assert "type" not in patched_dict |