def test_reorderm(m): def invert_inner(d): return {k: u.invertm(v) for k, v in d.items()} flipped = u.flipm(m) # flipping the inner map. assert u.reorderm(m, (0, 2, 1)) == invert_inner(m) # Flipping the outer keys is equivalent to calling flipm once. assert u.reorderm(m, (1, 0, 2)) == flipped # Reordering the inner keys is equiv to flipping the outer keys the # flipping the new inner dictionary. assert u.reorderm(m, (1, 2, 0)) == invert_inner(flipped) # Flipping again brings the original list entry out. assert u.reorderm(m, (2, 1, 0)) == u.flipm(invert_inner(flipped))
MachineType.highcpu_64: { GPU.K80: {8}, GPU.P4: {4}, GPU.P100: {4}, GPU.T4: {4}, GPU.V100: {8} }, MachineType.highcpu_96: { GPU.P4: {4}, GPU.T4: {4}, GPU.V100: {8} } } # : Dict[Accelerator, Dict[MachineType, Set[int]]] _AccelMTCount = u.reorderm(COMPATIBILITY_TABLE, (1, 0, 2)) # : Dict[Accelerator, Dict[int, Set[MachineType]]] _AccelCountMT = u.reorderm(COMPATIBILITY_TABLE, (1, 2, 0)) def accelerator_name(is_gpu: bool) -> str: return "GPU" if is_gpu else "TPU" def with_advice_suffix(accel: Union[Accelerator, str], s: str) -> str: """Accepts either an accelerator instance or a string as its first arg (the str can be 'gpu' or 'tpu', or any cased version of those) and a message string. Returns a string with a suffix appended that links to the GPU or CPU breakdown page, depending on the accelerator type.