MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / MakeTensorFromOtherTensor

Function MakeTensorFromOtherTensor

oneflow/api/python/utils/tensor_utils.cpp:274–287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

272}
273
274Maybe<Tensor> MakeTensorFromOtherTensor(const std::shared_ptr<Tensor>& other,
275 const bool pin_memory) {
276 if (other->is_local()) {
277 const Symbol<Device>& device = JUST(other->device());
278 return functional::Copy(other, device->type(), device->device_id(), pin_memory);
279 } else {
280 const Symbol<NdSbp>& nd_sbp = JUST(other->nd_sbp());
281 const std::vector<Symbol<SbpParallel>>& sbp_tuple = *JUST(GetSbpList(nd_sbp));
282 std::vector<Symbol<SbpParallel>> grad_sbp_tuple;
283 // TODO:(zhaoluyang) global case support pin_memory
284 return functional::ToGlobal(other, JUST(other->parallel_desc()), sbp_tuple, grad_sbp_tuple,
285 /* check_meta */ false, /*copy=*/false);
286 }
287}
288
289Maybe<Tensor> MakeTensorFromOtherTensor(const std::shared_ptr<Tensor>& other,
290 const Optional<Symbol<DType>>& dtype,

Callers 5

operator()Method · 0.85
operator()Method · 0.85
operator()Method · 0.85
operator()Method · 0.85
operator()Method · 0.85

Calls 14

CopyClass · 0.85
GlobalToLocalClass · 0.85
NewFunction · 0.50
CastClass · 0.50
is_localMethod · 0.45
deviceMethod · 0.45
typeMethod · 0.45
device_idMethod · 0.45
nd_sbpMethod · 0.45
parallel_descMethod · 0.45
has_valueMethod · 0.45
dtypeMethod · 0.45

Tested by

no test coverage detected