Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ColossalAI
Commits
e76f76c0
Unverified
Commit
e76f76c0
authored
Apr 28, 2022
by
Jiarui Fang
Committed by
GitHub
Apr 28, 2022
Browse files
[Tensor] test parameters() as member function (#896)
parent
cb182da7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
1 deletion
+31
-1
tests/test_tensor/test_model.py
tests/test_tensor/test_model.py
+31
-1
No files found.
tests/test_tensor/test_model.py
View file @
e76f76c0
...
...
@@ -98,6 +98,35 @@ def run_1d_col_tp():
if
i
>
5
:
break
# Test the overrided parameters() and named_parameters() member functions
def
test_model_parameters
():
# build a module with 2 Linear, 4 parameters in total.
class
Net
(
torch
.
nn
.
Module
):
def
__init__
(
self
):
super
().
__init__
()
self
.
fcs
=
torch
.
nn
.
Sequential
(
torch
.
nn
.
Linear
(
2
,
3
),
torch
.
nn
.
Linear
(
3
,
2
))
self
.
extra_param
=
torch
.
nn
.
Parameter
(
torch
.
randn
(
2
))
with
ColoInitContext
(
device
=
get_current_device
()):
model
=
Net
()
param_cnt
=
0
for
name
,
p
in
model
.
named_parameters
():
param_cnt
+=
1
assert
param_cnt
==
5
param_cnt
=
0
for
name
,
p
in
model
.
named_parameters
(
recurse
=
False
):
param_cnt
+=
1
assert
param_cnt
==
1
param_cnt
=
0
for
p
in
model
.
fcs
[
0
].
parameters
(
recurse
=
False
):
param_cnt
+=
1
assert
param_cnt
==
2
def
run_1d_row_tp
():
# A simple net with two stacked nn.Linear
get_components_func
=
non_distributed_component_funcs
.
get_callable
(
'simple_net'
)
...
...
@@ -179,4 +208,5 @@ def test_simple_net(world_size):
if
__name__
==
'__main__'
:
test_simple_net
()
# test_simple_net()
test_model_parameters
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment