MCPcopy
hub / github.com/InternLM/InternLM / is_first_rank

Method is_first_rank

internlm/core/context/parallel_context.py:265–279  ·  view source on GitHub ↗

Returns a boolean value indicating whether the current device is the first one among its group for `parallel_mode`. Args: parallel_mode: The chosen parallel mode. Returns: bool: a boolean value indicating whether the current device is the first one

(self, parallel_mode: ParallelMode)

Source from the content-addressed store, hash-verified

263 # return gpc.is_initialized(ParallelMode.SEQUENCE) and gpc.get_world_size(ParallelMode.SEQUENCE) > 1
264
265 def is_first_rank(self, parallel_mode: ParallelMode):
266 """Returns a boolean value indicating whether the current device is the first one
267 among its group for `parallel_mode`.
268
269 Args:
270 parallel_mode: The chosen parallel mode.
271
272 Returns:
273 bool: a boolean value indicating whether the current device is the first one
274 among its group for `parallel_mode`.
275 """
276 rank = 0
277 if self.is_initialized(parallel_mode):
278 rank = self.get_local_rank(parallel_mode)
279 return rank == 0
280
281 def is_rank_for_log(self):
282 """Returns a boolean value indicating whether the current device should print log."""

Callers 5

is_rank_for_logMethod · 0.95
_forward_only_stepMethod · 0.80

Calls 2

is_initializedMethod · 0.95
get_local_rankMethod · 0.95

Tested by

no test coverage detected