Esempio n. 1
0
def decode_random(
    shape: Sequence[int],
    dtype: flow.dtype,
    batch_size: int = 1,
    initializer: Optional[initializer_conf_util.InitializerConf] = None,
    tick: Optional[oneflow._oneflow_internal.BlobDesc] = None,
    name: Optional[str] = None,
) -> oneflow._oneflow_internal.BlobDesc:
    op_conf = op_conf_util.OperatorConf()
    if name is None:
        name = id_util.UniqueStr("DecodeRandom_")
    assert isinstance(name, str)
    op_conf.name = name
    assert isinstance(shape, (list, tuple))
    op_conf.decode_random_conf.shape.dim.extend(shape)
    assert dtype is not None
    setattr(
        op_conf.decode_random_conf,
        "data_type",
        oneflow._oneflow_internal.deprecated.GetProtoDtype4OfDtype(dtype),
    )
    op_conf.decode_random_conf.batch_size = batch_size
    if initializer is not None:
        op_conf.decode_random_conf.data_initializer.CopyFrom(initializer)
    else:
        op_conf.decode_random_conf.data_initializer.CopyFrom(
            flow.random_uniform_initializer())
    if tick:
        op_conf.decode_random_conf.tick = tick.unique_name
    op_conf.decode_random_conf.out = "out"
    lbi = logical_blob_id_util.LogicalBlobId()
    lbi.op_name = op_conf.name
    lbi.blob_name = "out"
    interpret_util.ConsistentForward(op_conf)
    return remote_blob_util.RemoteBlob(lbi)
Esempio n. 2
0
def distribute_add(xs, name=None):
    assert flow.current_scope(
    ).device_parallel_desc_symbol.parallel_num == len(xs)
    if name is None:
        name = id_util.UniqueStr("DistributeAdd_")
    op_conf = op_conf_util.OperatorConf()
    op_conf.name = name
    getattr(op_conf.distribute_add_conf,
            "in").extend([_SoleConsistentLbn(x) for x in xs])
    op_conf.distribute_add_conf.out = "out"
    interpret_util.ConsistentForward(op_conf)
    lbi = logical_blob_id_util.LogicalBlobId()
    lbi.op_name = op_conf.name
    lbi.blob_name = "out"
    return remote_blob_util.RemoteBlob(lbi)
Esempio n. 3
0
def distribute_clone(x, name=None):
    if name is None:
        name = id_util.UniqueStr("DistributeClone_")
    op_conf = op_conf_util.OperatorConf()
    op_conf.name = name
    setattr(op_conf.distribute_clone_conf, "in", x.unique_name)
    parallel_size = flow.current_scope(
    ).device_parallel_desc_symbol.parallel_num
    op_conf.distribute_clone_conf.out.extend(
        ["out_%d" % i for i in range(parallel_size)])
    interpret_util.ConsistentForward(op_conf)
    ret = []
    for i in range(parallel_size):
        out = "out_%d" % i
        lbi = logical_blob_id_util.LogicalBlobId()
        lbi.op_name = op_conf.name
        lbi.blob_name = out
        ret.append(remote_blob_util.RemoteBlob(lbi))
    return tuple(ret)
Esempio n. 4
0
 def InferAndTryRun(self):
     interpret_util.ConsistentForward(self.op_conf_)
     return self