forked from karpathy/nanoGPT
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathmanager.py
More file actions
29 lines (21 loc) · 709 Bytes
/
manager.py
File metadata and controls
29 lines (21 loc) · 709 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
class MOEManager:
"""
basic wrapper class for tracking, storing, and aggregating auxiliary
losses across multiple MoE layers in the model
"""
def __init__(self):
self.aux_loss = []
self.router_z_loss = []
def reset_aux_loss(self):
self.aux_loss = []
def reset_router_z_loss(self):
self.router_z_loss = []
def add_aux_loss(self, loss):
self.aux_loss.append(loss)
def add_router_z_loss(self, loss):
self.router_z_loss.append(loss)
def aggregate_aux_loss(self):
return sum(self.aux_loss)
def aggregate_router_z_loss(self):
return sum(self.router_z_loss)
MANAGER = MOEManager()