MCPcopy Create free account
hub / github.com/pytorch/pytorch / _test_join_base

Method _test_join_base

test/distributed/algorithms/test_join.py:203–276  ·  view source on GitHub ↗

r""" Skeleton for all :class:`Join` tests. Arguments: uneven_inputs (bool): ``True`` to use uneven inputs; ``False`` otherwise. num_joinables (int): number of :class:`AllReducer` s to construct. enable (bool): ``True`` to enable th

(
        self,
        uneven_inputs: bool,
        num_joinables: int,
        enable: bool,
        throw_on_early_termination: bool,
        num_allreduces: int,
        run_post_hooks: bool,
        expected_total: Optional[int] = None,
    )

Source from the content-addressed store, hash-verified

201 return 1
202
203 def _test_join_base(
204 self,
205 uneven_inputs: bool,
206 num_joinables: int,
207 enable: bool,
208 throw_on_early_termination: bool,
209 num_allreduces: int,
210 run_post_hooks: bool,
211 expected_total: Optional[int] = None,
212 ):
213 r"""
214 Skeleton for all :class:`Join` tests.
215
216 Arguments:
217 uneven_inputs (bool): ``True`` to use uneven inputs; ``False``
218 otherwise.
219 num_joinables (int): number of :class:`AllReducer` s to construct.
220 enable (bool): ``True`` to enable the join context manager;
221 ``False`` otherwise.
222 throw_on_early_termination (bool): ``True`` to raise an exception
223 upon detecting uneven inputs; ``False`` otherwise.
224 num_allreduces (int): number of all-reduces to perform per input.
225 run_post_hooks (bool): ``True`` to run post-hooks; ``False``
226 otherwise.
227 expected_total (Optional[int]): ``None`` to not check the expected
228 all-reduce total; otherwise, the expected total; default is
229 ``None``.
230 """
231 self.dist_init(self.rank, self.world_size)
232
233 allreducers = [
234 AllReducer(self.device, self.process_group)
235 for _ in range(num_joinables)
236 ]
237 for allreducer in allreducers:
238 self.assertEqual(allreducer.post_hook_tensor.item(), BEFORE_CONSTANT)
239
240 inputs = self.construct_uneven_inputs(self.base_num_inputs, self.offset) \
241 if uneven_inputs \
242 else self.construct_even_inputs(self.base_num_inputs)
243 allreduce_total = 0
244
245 # Expect a `RuntimeError` if `throw_on_early_termination=True`
246 # Rank 0 exhausts its inputs first
247 expected_msg = "Rank 0 exhausted all inputs." if self.rank == 0 \
248 else "Detected at least one rank that exhausted inputs. " \
249 "Throwing across all ranks."
250 with self.assertRaisesRegex(
251 RuntimeError,
252 expected_msg
253 ) if throw_on_early_termination else contextlib.nullcontext():
254 with Join(
255 allreducers,
256 enable=enable,
257 throw_on_early_termination=throw_on_early_termination,
258 num_allreduces=num_allreduces,
259 run_post_hooks=run_post_hooks
260 ):

Calls 9

dist_initMethod · 0.95
construct_even_inputsMethod · 0.95
JoinClass · 0.90
AllReducerClass · 0.85
itemMethod · 0.80
assertRaisesRegexMethod · 0.80
rangeFunction · 0.50
assertEqualMethod · 0.45

Tested by

no test coverage detected