Skip to content

Commit c0de453

Browse files
committed
add some useful decorators
1 parent 164943c commit c0de453

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/accelerate/decorator.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from functools import wraps
2+
3+
4+
def on_main_process(func):
5+
"""
6+
Run func on main process only
7+
"""
8+
9+
@wraps(func)
10+
def wrapper(self, *args, **kwargs):
11+
if self.is_main_process or not self.use_distributed:
12+
return func(self, *args, **kwargs)
13+
14+
return wrapper
15+
16+
17+
def on_local_main_process(func):
18+
"""
19+
Run func on local main process only
20+
"""
21+
22+
@wraps(func)
23+
def wrapper(self, *args, **kwargs):
24+
if self.is_local_main_process or not self.use_distributed:
25+
return func(self, *args, **kwargs)
26+
27+
return wrapper

0 commit comments

Comments
 (0)