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
4575a329
Unverified
Commit
4575a329
authored
Apr 22, 2022
by
Jiarui Fang
Committed by
GitHub
Apr 22, 2022
Browse files
[hotfix] ColoTensor pin_memory (#840)
parent
9f6f6569
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
9 deletions
+13
-9
colossalai/tensor/colo_tensor.py
colossalai/tensor/colo_tensor.py
+13
-9
No files found.
colossalai/tensor/colo_tensor.py
View file @
4575a329
...
...
@@ -20,21 +20,27 @@ class ColoTensor(object):
dtype
=
None
,
requires_grad
=
False
,
pin_memory
=
False
,
device
=
None
,
torch_tensor
=
torch
.
empty
(
0
),
):
self
.
_size
=
size
self
.
_dtype
=
dtype
self
.
_requires_grad
=
requires_grad
self
.
_pin_memory
=
pin_memory
self
.
_device
=
device
self
.
_torch_tensor
=
torch_tensor
def
numel
(
self
):
return
sum
(
self
.
_size
)
@
staticmethod
def
init_from_torch_tensor
(
tensor
:
torch
.
Tensor
)
:
def
init_from_torch_tensor
(
tensor
:
torch
.
Tensor
,
save_payload
=
True
)
->
'ColoTensor'
:
colo_t
=
ColoTensor
(
*
tensor
.
size
(),
dtype
=
tensor
.
dtype
,
requires_grad
=
tensor
.
requires_grad
,
pin_memory
=
tensor
.
pin_memory
,
torch_tensor
=
tensor
)
pin_memory
=
tensor
.
is_pinned
(),
device
=
tensor
.
device
,
torch_tensor
=
tensor
if
save_payload
else
torch
.
empty
(
0
))
return
colo_t
def
del_torch_tensor
(
self
)
->
None
:
...
...
@@ -42,12 +48,12 @@ class ColoTensor(object):
self
.
_torch_tensor
=
torch
.
empty
(
self
.
_size
)
def
torch_tensor
(
self
)
->
torch
.
Tensor
:
if
self
.
_torch_tensor
==
None
or
self
.
_torch_tensor
.
numel
()
==
0
:
print
(
self
.
_size
,
type
(
self
.
_size
))
if
self
.
_torch_tensor
.
numel
()
==
0
:
self
.
_torch_tensor
=
torch
.
empty
(
*
self
.
_size
,
dtype
=
self
.
_dtype
,
pin_memory
=
self
.
_pin_memory
,
requires_grad
=
self
.
_requires_grad
,
pin_memory
=
self
.
_pin_memory
)
device
=
self
.
_device
)
return
self
.
_torch_tensor
@
classmethod
...
...
@@ -67,7 +73,5 @@ class ColoTensor(object):
if
kwargs
is
None
:
kwargs
=
{}
kwargs
=
{
k
:
v
.
torch_tensor
()
if
isinstance
(
v
,
ColoTensor
)
else
v
for
k
,
v
in
kwargs
.
items
()
}
kwargs
=
{
k
:
v
.
torch_tensor
()
if
isinstance
(
v
,
ColoTensor
)
else
v
for
k
,
v
in
kwargs
.
items
()}
return
func
(
*
args
,
**
kwargs
)
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