text stringlengths 0 2.2M |
|---|
((self.device().is_cuda() && cuda_enabled) ||
|
(self.device().is_cpu() && cpu_enabled))
|
) {
|
at::ScalarType target = at::ScalarType::Undefined;
|
if (self.device().is_cuda()) {
|
target = cuda_dtype;
|
} else if (self.device().is_cpu()) {
|
target = cpu_dtype;
|
}
|
TORCH_INTERNAL_ASSERT(target != at::ScalarType::Undefined, "_autocast_to_reduced_precision requires legit ScalarType argument for given device");
|
return to_impl(
|
self, target, c10::nullopt, c10::nullopt, c10::nullopt, false, false, c10::nullopt);
|
} else {
|
return self;
|
}
|
}
|
// If input tensor is fp16, cast it to fp32, otherwise leave it alone.
|
// (this is intended to be used internally by the JIT autocast implementation)
|
Tensor _autocast_to_full_precision(const Tensor& self, bool cuda_enabled, bool cpu_enabled) {
|
if ((self.dtype() == at::ScalarType::Half || self.dtype() == at::ScalarType::BFloat16) &&
|
((self.device().is_cuda() && cuda_enabled) ||
|
(self.device().is_cpu() && cpu_enabled))
|
) {
|
return to_impl(
|
self, at::ScalarType::Float, c10::nullopt, c10::nullopt, c10::nullopt, false, false, c10::nullopt);
|
} else {
|
return self;
|
}
|
}
|
Tensor to(
|
const Tensor& self,
|
c10::optional<ScalarType> dtype,
|
c10::optional<Layout> layout,
|
c10::optional<Device> device,
|
c10::optional<bool> pin_memory,
|
bool non_blocking,
|
bool copy,
|
c10::optional<c10::MemoryFormat> optional_memory_format
|
) {
|
return to_impl(
|
self,
|
dtype,
|
layout,
|
ensure_has_index(device),
|
pin_memory,
|
non_blocking,
|
copy,
|
optional_memory_format);
|
}
|
Tensor to(const Tensor& self, Device device, ScalarType dtype, bool non_blocking, bool copy, c10::optional<c10::MemoryFormat> optional_memory_format) {
|
return to_impl(
|
self,
|
dtype,
|
nullopt,
|
ensure_has_index(device),
|
nullopt,
|
non_blocking,
|
copy,
|
optional_memory_format);
|
}
|
Tensor to(const Tensor& self, ScalarType dtype, bool non_blocking, bool copy, c10::optional<c10::MemoryFormat> optional_memory_format) {
|
return to_impl(
|
self,
|
dtype,
|
nullopt,
|
nullopt,
|
nullopt,
|
non_blocking,
|
copy,
|
optional_memory_format);
|
}
|
Tensor to(const Tensor& self, const Tensor& other, bool non_blocking, bool copy, c10::optional<c10::MemoryFormat> optional_memory_format) {
|
auto options = other.options();
|
return to_impl(
|
self,
|
options.dtype().toScalarType(),
|
options.layout(),
|
options.device(),
|
options.pinned_memory(),
|
non_blocking,
|
copy,
|
optional_memory_format);
|
}
|
// This op is important primarily for lazy / graph-based backends.
|
// While this vanilla implementation loops through each tensor and independently converts it to cpu,
|
// a lazy backend like XLA might need to tell sync updates across tensors.
|
std::vector<Tensor> _to_cpu(TensorList tensors) {
|
std::vector<Tensor> cpu_tensors;
|
for (const auto& t : tensors) {
|
cpu_tensors.push_back(t.cpu());
|
}
|
return cpu_tensors;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.