예제 #1
0
 def testAxisIndex(self):
   device_count = xla_bridge.device_count()
   f = pmap(lambda x: x + pxla.axis_index('i'), 'i')
   x = np.ones(device_count)
   ans = f(x)
   expected = 1 + onp.arange(device_count)
   self.assertAllClose(ans, expected, check_dtypes=False)
예제 #2
0
def _allgather(x, dim, size, axis_name):
    shape = list(x.shape)
    shape.insert(dim, size)
    out = lax.full(shape, lax._const(x, 0))
    out = lax.dynamic_update_index_in_dim(out, x, axis_index(axis_name), dim)
    return psum(out, axis_name)
예제 #3
0
def _drop(x, dim, axis_name):
    return lax.dynamic_index_in_dim(x, axis_index(axis_name), dim, False)
예제 #4
0
def _expand(dim, size, axis_name, x):
    shape = list(x.shape)
    shape.insert(dim, size)
    out = lax.full(shape, lax._const(x, 0))
    return lax.dynamic_update_index_in_dim(out, x, axis_index(axis_name), dim)