MCPcopy Create free account
hub / github.com/PRIME-RL/PRIME / MegatronMemoryBufferForRollout

Class MegatronMemoryBufferForRollout

training/verl/utils/memory_buffer.py:160–214  ·  view source on GitHub ↗

We assume that - inference engine has tp + dp - actor has tp + pp + dp - the tp between inference engine and actor should be the same - memory_buffers: contains a list of memory_buffers, each is a dict from dtype to MemoryBuffer - weight_buffers: contains a list of weight_bu

Source from the content-addressed store, hash-verified

158
159
160class MegatronMemoryBufferForRollout(object):
161 """
162 We assume that
163 - inference engine has tp + dp
164 - actor has tp + pp + dp
165 - the tp between inference engine and actor should be the same
166 - memory_buffers: contains a list of memory_buffers, each is a dict from dtype to MemoryBuffer
167 - weight_buffers: contains a list of weight_buffers, each is a dict from name to param
168 - named_parameters: a dict from name to parameter that normalizes the names from pp and vpp. Note that
169 the named_parameters may not be directly compatible with inference engine. User has to take care of
170 this part such as the layout mismatches. (e.g. qkv transpose)
171 - Note that weight_buffer, named_parameters and memory_buffers share the same underlying GPU memory.
172 - When doing weight sync, the data is transfer via memory buffers
173 """
174
175 def __init__(self, transform_memory_param_fn):
176 self._memory_buffers = []
177 self._weight_buffers = []
178 self._named_parameters = {}
179 self.transform_memory_param_fn = transform_memory_param_fn
180
181 def initialize_weight_buffer(self, weight_buffer_meta_pp: List[Dict[str, Dict]]):
182 """
183 Initialize the weight buffer. The weight buffer is obtained according to the actor. We will construct
184 a large buffer for each dtype in the weight_buffer.
185
186 Args:
187 weight_buffer_meta: contains pp models, each pp models contains a dictionary of mapping from
188
189 Returns: None
190
191 """
192 self.weight_buffer_meta_pp = weight_buffer_meta_pp
193
194 for weight_buffer_meta in self.weight_buffer_meta_pp:
195 memory_buffer = build_memory_buffer(weight_buffer_meta)
196 self._memory_buffers.append(memory_buffer)
197 self._weight_buffers.append(None)
198
199 def build_memory_reference(self):
200 for i, weight_buffer_meta in enumerate(self.weight_buffer_meta_pp):
201 self._weight_buffers[i] = build_memory_reference(weight_buffer_meta, self._memory_buffers[i])
202 self._named_parameters = self.transform_memory_param_fn(self._weight_buffers)
203
204 @property
205 def named_parameters(self):
206 return self._named_parameters
207
208 @property
209 def weight_buffers(self):
210 return self._weight_buffers
211
212 @property
213 def memory_buffers(self):
214 return self._memory_buffers

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected