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
54e688b6
Unverified
Commit
54e688b6
authored
Apr 01, 2022
by
アマデウス
Committed by
GitHub
Apr 01, 2022
Browse files
moved ensure_path_exists to utils.common (#591)
parent
e956d93a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
2 deletions
+10
-2
colossalai/utils/common.py
colossalai/utils/common.py
+10
-2
No files found.
colossalai/utils/common.py
View file @
54e688b6
#!/usr/bin/env python
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# -*- encoding: utf-8 -*-
import
os
import
random
import
random
import
socket
import
socket
from
pathlib
import
Path
from
typing
import
List
,
Union
from
typing
import
List
,
Union
import
torch
import
torch
...
@@ -39,6 +41,13 @@ def print_rank_0(msg: str, logger=None):
...
@@ -39,6 +41,13 @@ def print_rank_0(msg: str, logger=None):
logger
.
info
(
msg
)
logger
.
info
(
msg
)
def
ensure_path_exists
(
filename
:
str
):
# ensure the path exists
dirpath
=
os
.
path
.
dirname
(
filename
)
if
not
os
.
path
.
exists
(
dirpath
):
Path
(
dirpath
).
mkdir
(
parents
=
True
,
exist_ok
=
True
)
def
free_port
():
def
free_port
():
while
True
:
while
True
:
try
:
try
:
...
@@ -103,7 +112,6 @@ def conditional_context(context_manager, enable=True):
...
@@ -103,7 +112,6 @@ def conditional_context(context_manager, enable=True):
class
model_branch_context
(
object
):
class
model_branch_context
(
object
):
def
__enter__
(
self
):
def
__enter__
(
self
):
self
.
env_status
=
env
.
save
()
self
.
env_status
=
env
.
save
()
...
@@ -123,7 +131,7 @@ def _calc_l2_norm(grads):
...
@@ -123,7 +131,7 @@ def _calc_l2_norm(grads):
colossal_C
.
multi_tensor_l2norm
,
colossal_C
.
multi_tensor_l2norm
,
dummy_overflow_buf
,
dummy_overflow_buf
,
[
grads
],
[
grads
],
False
# no per-parameter norm
False
# no per-parameter norm
)
)
return
norm
return
norm
...
...
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