示例#1
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)
示例#2
0
def _empty_array(sz, aval):
  if aval is core.abstract_unit:
    return core.unit
  else:
    return lax.full((sz,) + aval.shape, 0, aval.dtype)
示例#3
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)
示例#4
0
def _empty_arrays(aval):
  assert isinstance(aval, core.AbstractValue)
  if isinstance(aval, core.AbstractTuple):
    return core.pack(map(_empty_arrays, aval))
  else:
    return lax.full(aval.shape, 0, aval.dtype)