/usr/local/lib64/python3.6/site-packages/torch/include/torch/csrc/utils
NameSizeModeActions
auto_gil.h10340644editdlrm
byte_order.h24840644editdlrm
crash_handler.h11460644editdlrm
cuda_enabled.h1540644editdlrm
cuda_lazy_init.h9740644editdlrm
disable_torch_function.h8630644editdlrm
disallow_copy.h1030644editdlrm
init.h3240644editdlrm
invalid_arguments.h3020644editdlrm
memory.h11730644editdlrm
numpy_stub.h3990644editdlrm
object_ptr.h13290644editdlrm
out_types.h2940644editdlrm
pybind.h79660644editdlrm
pycfunction_helpers.h2090644editdlrm
python_arg_parser.h307530644editdlrm
python_compat.h29040644editdlrm
python_dispatch.h1740644editdlrm
python_numbers.h50640644editdlrm
python_scalars.h29280644editdlrm
python_strings.h45920644editdlrm
python_stub.h560644editdlrm
python_tuples.h6840644editdlrm
six.h14250644editdlrm
structseq.h1530644editdlrm
tensor_apply.h4310644editdlrm
tensor_dtypes.h2440644editdlrm
tensor_flatten.h27800644editdlrm
tensor_layouts.h1070644editdlrm
tensor_list.h1960644editdlrm
tensor_memoryformats.h1130644editdlrm
tensor_new.h18070644editdlrm
tensor_numpy.h5420644editdlrm
tensor_qschemes.h1860644editdlrm
tensor_types.h4910644editdlrm
throughput_benchmark-inl.h52100644editdlrm
throughput_benchmark.h68680644editdlrm
variadic.h43940644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/torch/include/torch/csrc/utils/tensor_flatten.h (2780B)
#pragma once #include #include #include #include #include namespace torch { namespace utils { /// Generate an ID for a combination of tensor backend + scalar type to be used /// when ordering tensors ('like' tensors are grouped by pulling out their /// backend + scalar type, so this function combines that into a single number) inline size_t type_id(const at::Tensor& tensor) { return static_cast(tensor.options().backend()) * static_cast(at::ScalarType::NumOptions) + static_cast(tensor.scalar_type()); } inline at::Tensor flatten_dense_tensors(at::TensorList tensors) { return at::flatten_dense_tensors(tensors); } inline std::vector unflatten_dense_tensors(const at::Tensor& flat, at::TensorList tensors) { return at::unflatten_dense_tensors(flat, tensors); } // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) struct TensorGroup { std::vector tensors; size_t size = 0; size_t type_id() { AT_ASSERT(!tensors.empty()); return ::torch::utils::type_id(tensors[0]); } const at::TensorOptions options() { AT_ASSERT(!tensors.empty()); return tensors[0].options(); } }; // Helper function that takes a list of tensors and splits them into tensor // groups by the size limit and outputs these tensor groups. If the input // tensors are of different tensor types, they will be split into different // groups as well. // // Two options of splitting provided to the user, // // Imagine the size_limit is 256 and the list of input tensors are: // tensor_a(fp16 - 128 bytes), // tensor_b(fp32 - 256 bytes), // tensor_c(fp16 - 128 bytes), // // when fine_grained == false: // The function will read the list of tensors sequentially and accumulate // enough tensors for each data type until the size_limit, therefore: // it will output: {{tensor_a, tensor_c}, {tensor_b}} // // when fine_grained == true: // The function will read the list of tensors sequentially and accumulate // enough tensors for all data types until the size_limit, and then split // the accumulated tensors into different groups by data types, therefore: // it will output: {{tensor_a}, {tensor_b}, {tensor_c}} TORCH_API std::vector take_tensors( at::TensorList tensors, size_t size_limit, bool fine_grained = false); TORCH_API void reorder_tensors_like(std::vector& tensors, at::TensorList order); TORCH_API std::pair flatten_sparse_tensors(at::TensorList tensors); TORCH_API std::vector unflatten_sparse_tensors( const at::Tensor& flat_indices, const at::Tensor& flat_values, at::TensorList tensors); }}