-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_utils.py
More file actions
46 lines (36 loc) · 876 Bytes
/
memory_utils.py
File metadata and controls
46 lines (36 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from megatron_patch.memory.trainer_v5 import TrainerMemoryManager
from megatron_patch.memory.inference_manager import InferenceMemoryManager
import torch
def megatron_model(model):
if isinstance(model, list):
assert len(model) == 1
model = model[0]
else:
model = model
return model
def create_trainer_memory_manager(
model,
optimizer,
bucket_size_mb=0,
) :
"""
Create a trainer memory manager based on megatron version.
"""
cls = TrainerMemoryManager
return cls(
model,
optimizer,
bucket_size_mb,
)
def create_inference_memory_manager(
model,
bucket_size_mb=0,
) :
"""
Create a trainer memory manager based on megatron version.
"""
cls = InferenceMemoryManager
return cls(
model,
bucket_size_mb,
)