diff --git a/.gitattributes b/.gitattributes index 501da003a2a8fa7ec167ba29b2b8c16c0e77fcba..000a348c85d6d30339e7c6fc9ce27915c6621658 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1482,3 +1482,4 @@ parrot/lib/python3.10/site-packages/scipy/stats/__pycache__/_mstats_basic.cpytho parrot/lib/python3.10/site-packages/numpy/random/_pcg64.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text parrot/lib/python3.10/site-packages/scipy/stats/tests/__pycache__/test_distributions.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text parrot/lib/python3.10/site-packages/scipy/constants/__pycache__/_codata.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text +vllm/lib/python3.10/site-packages/ray/_private/__pycache__/worker.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text diff --git a/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_fake_quantize_learnable_per_tensor_affine_backward_cpu_dispatch.h b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_fake_quantize_learnable_per_tensor_affine_backward_cpu_dispatch.h new file mode 100644 index 0000000000000000000000000000000000000000..f2c222b11bb8dd66556b2554bc0b53e0468950bd --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_fake_quantize_learnable_per_tensor_affine_backward_cpu_dispatch.h @@ -0,0 +1,23 @@ +#pragma once +// @generated by torchgen/gen.py from DispatchKeyFunction.h + +// NB: The implementing C++ file is RegisterDispatchKey.cpp + +// The only #includes we need are for custom classes that have defaults in the C++ API +#include +#include +#include + +// Forward declarations of any types needed in the operator signatures. +// We can't directly include these classes because it will cause circular include dependencies. +// This file is included by TensorBody.h, which defines the Tensor class. +#include + +namespace at { + +namespace cpu { + +TORCH_API ::std::tuple _fake_quantize_learnable_per_tensor_affine_backward(const at::Tensor & grad, const at::Tensor & self, const at::Tensor & scale, const at::Tensor & zero_point, int64_t quant_min, int64_t quant_max, double grad_factor=1.0); + +} // namespace cpu +} // namespace at diff --git a/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_pack_padded_sequence_backward_compositeimplicitautograd_dispatch.h b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_pack_padded_sequence_backward_compositeimplicitautograd_dispatch.h new file mode 100644 index 0000000000000000000000000000000000000000..faecc96ae809434eb3ec6514a70c64fbb2ef803c --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/_pack_padded_sequence_backward_compositeimplicitautograd_dispatch.h @@ -0,0 +1,24 @@ +#pragma once +// @generated by torchgen/gen.py from DispatchKeyFunction.h + +// NB: The implementing C++ file is RegisterDispatchKey.cpp + +// The only #includes we need are for custom classes that have defaults in the C++ API +#include +#include +#include + +// Forward declarations of any types needed in the operator signatures. +// We can't directly include these classes because it will cause circular include dependencies. +// This file is included by TensorBody.h, which defines the Tensor class. +#include + +namespace at { + +namespace compositeimplicitautograd { + +TORCH_API at::Tensor _pack_padded_sequence_backward(const at::Tensor & grad, at::IntArrayRef input_size, const at::Tensor & batch_sizes, bool batch_first); +TORCH_API at::Tensor _pack_padded_sequence_backward_symint(const at::Tensor & grad, c10::SymIntArrayRef input_size, const at::Tensor & batch_sizes, bool batch_first); + +} // namespace compositeimplicitautograd +} // namespace at diff --git a/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/add_ops.h b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/add_ops.h new file mode 100644 index 0000000000000000000000000000000000000000..e19bc4649a705a29bd9aed8c728a384221b05735 --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/add_ops.h @@ -0,0 +1,83 @@ +#pragma once + +// @generated by torchgen/gen.py from Operator.h + +#include +#include + +// Forward declarations of any types needed in the operator signatures. +// We can't directly include these classes because it will cause circular include dependencies. +// This file is included by TensorBody.h, which defines the Tensor class. +#include + +namespace at { +namespace _ops { + + +struct TORCH_API add_Tensor { + using schema = at::Tensor (const at::Tensor &, const at::Tensor &, const at::Scalar &); + using ptr_schema = schema*; + // See Note [static constexpr char* members for windows NVCC] + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::add") + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "Tensor") + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) -> Tensor") + static at::Tensor call(const at::Tensor & self, const at::Tensor & other, const at::Scalar & alpha); + static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, const at::Tensor & other, const at::Scalar & alpha); +}; + +struct TORCH_API add__Tensor { + using schema = at::Tensor & (at::Tensor &, const at::Tensor &, const at::Scalar &); + using ptr_schema = schema*; + // See Note [static constexpr char* members for windows NVCC] + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::add_") + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "Tensor") + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "add_.Tensor(Tensor(a!) self, Tensor other, *, Scalar alpha=1) -> Tensor(a!)") + static at::Tensor & call(at::Tensor & self, const at::Tensor & other, const at::Scalar & alpha); + static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, at::Tensor & self, const at::Tensor & other, const at::Scalar & alpha); +}; + +struct TORCH_API add_out { + using schema = at::Tensor & (const at::Tensor &, const at::Tensor &, const at::Scalar &, at::Tensor &); + using ptr_schema = schema*; + // See Note [static constexpr char* members for windows NVCC] + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::add") + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "out") + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "add.out(Tensor self, Tensor other, *, Scalar alpha=1, Tensor(a!) out) -> Tensor(a!)") + static at::Tensor & call(const at::Tensor & self, const at::Tensor & other, const at::Scalar & alpha, at::Tensor & out); + static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, const at::Tensor & other, const at::Scalar & alpha, at::Tensor & out); +}; + +struct TORCH_API add_Scalar { + using schema = at::Tensor (const at::Tensor &, const at::Scalar &, const at::Scalar &); + using ptr_schema = schema*; + // See Note [static constexpr char* members for windows NVCC] + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::add") + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "Scalar") + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "add.Scalar(Tensor self, Scalar other, Scalar alpha=1) -> Tensor") + static at::Tensor call(const at::Tensor & self, const at::Scalar & other, const at::Scalar & alpha); + static at::Tensor redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, const at::Scalar & other, const at::Scalar & alpha); +}; + +struct TORCH_API add__Scalar { + using schema = at::Tensor & (at::Tensor &, const at::Scalar &, const at::Scalar &); + using ptr_schema = schema*; + // See Note [static constexpr char* members for windows NVCC] + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::add_") + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "Scalar") + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "add_.Scalar(Tensor(a!) self, Scalar other, Scalar alpha=1) -> Tensor(a!)") + static at::Tensor & call(at::Tensor & self, const at::Scalar & other, const at::Scalar & alpha); + static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, at::Tensor & self, const at::Scalar & other, const at::Scalar & alpha); +}; + +struct TORCH_API add_Scalar_out { + using schema = at::Tensor & (const at::Tensor &, const at::Scalar &, const at::Scalar &, at::Tensor &); + using ptr_schema = schema*; + // See Note [static constexpr char* members for windows NVCC] + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(name, "aten::add") + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(overload_name, "Scalar_out") + STATIC_CONSTEXPR_STR_INL_EXCEPT_WIN_CUDA(schema_str, "add.Scalar_out(Tensor self, Scalar other, Scalar alpha=1, *, Tensor(a!) out) -> Tensor(a!)") + static at::Tensor & call(const at::Tensor & self, const at::Scalar & other, const at::Scalar & alpha, at::Tensor & out); + static at::Tensor & redispatch(c10::DispatchKeySet dispatchKeySet, const at::Tensor & self, const at::Scalar & other, const at::Scalar & alpha, at::Tensor & out); +}; + +}} // namespace at::_ops diff --git a/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/argmin_meta_dispatch.h b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/argmin_meta_dispatch.h new file mode 100644 index 0000000000000000000000000000000000000000..1bede8da2134ee04fbf12b4ed5143a9726503a02 --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/argmin_meta_dispatch.h @@ -0,0 +1,25 @@ +#pragma once +// @generated by torchgen/gen.py from DispatchKeyFunction.h + +// NB: The implementing C++ file is RegisterDispatchKey.cpp + +// The only #includes we need are for custom classes that have defaults in the C++ API +#include +#include +#include + +// Forward declarations of any types needed in the operator signatures. +// We can't directly include these classes because it will cause circular include dependencies. +// This file is included by TensorBody.h, which defines the Tensor class. +#include + +namespace at { + +namespace meta { + +TORCH_API at::Tensor argmin(const at::Tensor & self, c10::optional dim=c10::nullopt, bool keepdim=false); +TORCH_API at::Tensor & argmin_out(at::Tensor & out, const at::Tensor & self, c10::optional dim=c10::nullopt, bool keepdim=false); +TORCH_API at::Tensor & argmin_outf(const at::Tensor & self, c10::optional dim, bool keepdim, at::Tensor & out); + +} // namespace meta +} // namespace at diff --git a/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/baddbmm_cuda_dispatch.h b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/baddbmm_cuda_dispatch.h new file mode 100644 index 0000000000000000000000000000000000000000..61d35bdfb5a076dfa8192ac8c7eb6f119e82caf4 --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/baddbmm_cuda_dispatch.h @@ -0,0 +1,26 @@ +#pragma once +// @generated by torchgen/gen.py from DispatchKeyFunction.h + +// NB: The implementing C++ file is RegisterDispatchKey.cpp + +// The only #includes we need are for custom classes that have defaults in the C++ API +#include +#include +#include + +// Forward declarations of any types needed in the operator signatures. +// We can't directly include these classes because it will cause circular include dependencies. +// This file is included by TensorBody.h, which defines the Tensor class. +#include + +namespace at { + +namespace cuda { + +TORCH_API at::Tensor baddbmm(const at::Tensor & self, const at::Tensor & batch1, const at::Tensor & batch2, const at::Scalar & beta=1, const at::Scalar & alpha=1); +TORCH_API at::Tensor & baddbmm_out(at::Tensor & out, const at::Tensor & self, const at::Tensor & batch1, const at::Tensor & batch2, const at::Scalar & beta=1, const at::Scalar & alpha=1); +TORCH_API at::Tensor & baddbmm_outf(const at::Tensor & self, const at::Tensor & batch1, const at::Tensor & batch2, const at::Scalar & beta, const at::Scalar & alpha, at::Tensor & out); +TORCH_API at::Tensor & baddbmm_(at::Tensor & self, const at::Tensor & batch1, const at::Tensor & batch2, const at::Scalar & beta=1, const at::Scalar & alpha=1); + +} // namespace cuda +} // namespace at diff --git a/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/empty_strided_compositeexplicitautograd_dispatch.h b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/empty_strided_compositeexplicitautograd_dispatch.h new file mode 100644 index 0000000000000000000000000000000000000000..8a71029694e1d7b9ddd8b10c991a14f0f0ef264d --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/empty_strided_compositeexplicitautograd_dispatch.h @@ -0,0 +1,26 @@ +#pragma once +// @generated by torchgen/gen.py from DispatchKeyFunction.h + +// NB: The implementing C++ file is RegisterDispatchKey.cpp + +// The only #includes we need are for custom classes that have defaults in the C++ API +#include +#include +#include + +// Forward declarations of any types needed in the operator signatures. +// We can't directly include these classes because it will cause circular include dependencies. +// This file is included by TensorBody.h, which defines the Tensor class. +#include + +namespace at { + +namespace compositeexplicitautograd { + +TORCH_API at::Tensor & empty_strided_out(at::Tensor & out, at::IntArrayRef size, at::IntArrayRef stride); +TORCH_API at::Tensor & empty_strided_outf(at::IntArrayRef size, at::IntArrayRef stride, at::Tensor & out); +TORCH_API at::Tensor & empty_strided_symint_out(at::Tensor & out, c10::SymIntArrayRef size, c10::SymIntArrayRef stride); +TORCH_API at::Tensor & empty_strided_symint_outf(c10::SymIntArrayRef size, c10::SymIntArrayRef stride, at::Tensor & out); + +} // namespace compositeexplicitautograd +} // namespace at diff --git a/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/lerp_compositeexplicitautogradnonfunctional_dispatch.h b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/lerp_compositeexplicitautogradnonfunctional_dispatch.h new file mode 100644 index 0000000000000000000000000000000000000000..c236873f881c152b00dd9fe191329df719486f0a --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/lerp_compositeexplicitautogradnonfunctional_dispatch.h @@ -0,0 +1,26 @@ +#pragma once +// @generated by torchgen/gen.py from DispatchKeyFunction.h + +// NB: The implementing C++ file is RegisterDispatchKey.cpp + +// The only #includes we need are for custom classes that have defaults in the C++ API +#include +#include +#include + +// Forward declarations of any types needed in the operator signatures. +// We can't directly include these classes because it will cause circular include dependencies. +// This file is included by TensorBody.h, which defines the Tensor class. +#include + +namespace at { + +namespace compositeexplicitautogradnonfunctional { + +TORCH_API at::Tensor lerp(const at::Tensor & self, const at::Tensor & end, const at::Scalar & weight); +TORCH_API at::Tensor & lerp_(at::Tensor & self, const at::Tensor & end, const at::Scalar & weight); +TORCH_API at::Tensor lerp(const at::Tensor & self, const at::Tensor & end, const at::Tensor & weight); +TORCH_API at::Tensor & lerp_(at::Tensor & self, const at::Tensor & end, const at::Tensor & weight); + +} // namespace compositeexplicitautogradnonfunctional +} // namespace at diff --git a/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/logit_backward_native.h b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/logit_backward_native.h new file mode 100644 index 0000000000000000000000000000000000000000..780e8b66f64a14eea6659add1d934151197e4f0c --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/logit_backward_native.h @@ -0,0 +1,23 @@ +#pragma once + +// @generated by torchgen/gen.py from NativeFunction.h + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace at { +namespace native { +struct TORCH_API structured_logit_backward_out : public at::meta::structured_logit_backward { +void impl(const at::Tensor & grad_output, const at::Tensor & self, c10::optional eps, const at::Tensor & grad_input); +}; +} // namespace native +} // namespace at diff --git a/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/lu_unpack_native.h b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/lu_unpack_native.h new file mode 100644 index 0000000000000000000000000000000000000000..997e542531196afcad5e45d320fa339313f648d0 --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/lu_unpack_native.h @@ -0,0 +1,23 @@ +#pragma once + +// @generated by torchgen/gen.py from NativeFunction.h + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace at { +namespace native { +struct TORCH_API structured_lu_unpack_out : public at::meta::structured_lu_unpack { +void impl(const at::Tensor & LU_data, const at::Tensor & LU_pivots, bool unpack_data, bool unpack_pivots, const at::Tensor & P, const at::Tensor & L, const at::Tensor & U); +}; +} // namespace native +} // namespace at diff --git a/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/native_batch_norm_cpu_dispatch.h b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/native_batch_norm_cpu_dispatch.h new file mode 100644 index 0000000000000000000000000000000000000000..50dd054b2223ccdf3aa700dc333ac14ea054060c --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/native_batch_norm_cpu_dispatch.h @@ -0,0 +1,25 @@ +#pragma once +// @generated by torchgen/gen.py from DispatchKeyFunction.h + +// NB: The implementing C++ file is RegisterDispatchKey.cpp + +// The only #includes we need are for custom classes that have defaults in the C++ API +#include +#include +#include + +// Forward declarations of any types needed in the operator signatures. +// We can't directly include these classes because it will cause circular include dependencies. +// This file is included by TensorBody.h, which defines the Tensor class. +#include + +namespace at { + +namespace cpu { + +TORCH_API ::std::tuple native_batch_norm(const at::Tensor & input, const c10::optional & weight, const c10::optional & bias, const c10::optional & running_mean, const c10::optional & running_var, bool training, double momentum, double eps); +TORCH_API ::std::tuple native_batch_norm_out(at::Tensor & out, at::Tensor & save_mean, at::Tensor & save_invstd, const at::Tensor & input, const c10::optional & weight, const c10::optional & bias, const c10::optional & running_mean, const c10::optional & running_var, bool training, double momentum, double eps); +TORCH_API ::std::tuple native_batch_norm_outf(const at::Tensor & input, const c10::optional & weight, const c10::optional & bias, const c10::optional & running_mean, const c10::optional & running_var, bool training, double momentum, double eps, at::Tensor & out, at::Tensor & save_mean, at::Tensor & save_invstd); + +} // namespace cpu +} // namespace at diff --git a/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/nonzero_native.h b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/nonzero_native.h new file mode 100644 index 0000000000000000000000000000000000000000..40a5a211dd714ce948228ab42a576a50e939c7b9 --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/nonzero_native.h @@ -0,0 +1,24 @@ +#pragma once + +// @generated by torchgen/gen.py from NativeFunction.h + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace at { +namespace native { +TORCH_API at::Tensor nonzero_cpu(const at::Tensor & self); +TORCH_API at::Tensor & nonzero_out_cpu(const at::Tensor & self, at::Tensor & out); +TORCH_API at::Tensor nonzero_cuda(const at::Tensor & self); +TORCH_API at::Tensor & nonzero_out_cuda(const at::Tensor & self, at::Tensor & out); +} // namespace native +} // namespace at diff --git a/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/special_legendre_polynomial_p.h b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/special_legendre_polynomial_p.h new file mode 100644 index 0000000000000000000000000000000000000000..4c692de9a799906d6d4f8a205ebed20f6b2d2dcd --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/special_legendre_polynomial_p.h @@ -0,0 +1,67 @@ +#pragma once + +// @generated by torchgen/gen.py from Function.h + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +#include + +namespace at { + + +// aten::special_legendre_polynomial_p(Tensor x, Tensor n) -> Tensor +inline at::Tensor special_legendre_polynomial_p(const at::Tensor & x, const at::Tensor & n) { + return at::_ops::special_legendre_polynomial_p::call(x, n); +} + +// aten::special_legendre_polynomial_p.x_scalar(Scalar x, Tensor n) -> Tensor +inline at::Tensor special_legendre_polynomial_p(const at::Scalar & x, const at::Tensor & n) { + return at::_ops::special_legendre_polynomial_p_x_scalar::call(x, n); +} + +// aten::special_legendre_polynomial_p.n_scalar(Tensor x, Scalar n) -> Tensor +inline at::Tensor special_legendre_polynomial_p(const at::Tensor & x, const at::Scalar & n) { + return at::_ops::special_legendre_polynomial_p_n_scalar::call(x, n); +} + +// aten::special_legendre_polynomial_p.out(Tensor x, Tensor n, *, Tensor(a!) out) -> Tensor(a!) +inline at::Tensor & special_legendre_polynomial_p_out(at::Tensor & out, const at::Tensor & x, const at::Tensor & n) { + return at::_ops::special_legendre_polynomial_p_out::call(x, n, out); +} +// aten::special_legendre_polynomial_p.out(Tensor x, Tensor n, *, Tensor(a!) out) -> Tensor(a!) +inline at::Tensor & special_legendre_polynomial_p_outf(const at::Tensor & x, const at::Tensor & n, at::Tensor & out) { + return at::_ops::special_legendre_polynomial_p_out::call(x, n, out); +} + +// aten::special_legendre_polynomial_p.x_scalar_out(Scalar x, Tensor n, *, Tensor(a!) out) -> Tensor(a!) +inline at::Tensor & special_legendre_polynomial_p_out(at::Tensor & out, const at::Scalar & x, const at::Tensor & n) { + return at::_ops::special_legendre_polynomial_p_x_scalar_out::call(x, n, out); +} +// aten::special_legendre_polynomial_p.x_scalar_out(Scalar x, Tensor n, *, Tensor(a!) out) -> Tensor(a!) +inline at::Tensor & special_legendre_polynomial_p_outf(const at::Scalar & x, const at::Tensor & n, at::Tensor & out) { + return at::_ops::special_legendre_polynomial_p_x_scalar_out::call(x, n, out); +} + +// aten::special_legendre_polynomial_p.n_scalar_out(Tensor x, Scalar n, *, Tensor(a!) out) -> Tensor(a!) +inline at::Tensor & special_legendre_polynomial_p_out(at::Tensor & out, const at::Tensor & x, const at::Scalar & n) { + return at::_ops::special_legendre_polynomial_p_n_scalar_out::call(x, n, out); +} +// aten::special_legendre_polynomial_p.n_scalar_out(Tensor x, Scalar n, *, Tensor(a!) out) -> Tensor(a!) +inline at::Tensor & special_legendre_polynomial_p_outf(const at::Tensor & x, const at::Scalar & n, at::Tensor & out) { + return at::_ops::special_legendre_polynomial_p_n_scalar_out::call(x, n, out); +} + +} diff --git a/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/sym_stride.h b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/sym_stride.h new file mode 100644 index 0000000000000000000000000000000000000000..280a226e7148ead10ec983ae90f523ed0d1276bb --- /dev/null +++ b/videollama2/lib/python3.10/site-packages/torch/include/ATen/ops/sym_stride.h @@ -0,0 +1,30 @@ +#pragma once + +// @generated by torchgen/gen.py from Function.h + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +#include + +namespace at { + + +// aten::sym_stride.int(Tensor self, int dim) -> SymInt +inline c10::SymInt __dispatch_sym_stride(const at::Tensor & self, int64_t dim) { + return at::_ops::sym_stride_int::call(self, dim); +} + +} diff --git a/vllm/lib/python3.10/site-packages/ray/_private/__pycache__/worker.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/_private/__pycache__/worker.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fda9aa57ffd14c2edcd5aa6cf7c9b69c963daf26 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/_private/__pycache__/worker.cpython-310.pyc @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:533616df3ad15bb7a8fd9a3e98b76407e4402a34776af33758cdd165caa17dec +size 105370 diff --git a/vllm/lib/python3.10/site-packages/ray/data/__pycache__/aggregate.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/__pycache__/aggregate.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..615e94aa77fabc20fe4f6c73610add7e7d6f9aa4 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/__pycache__/aggregate.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/__pycache__/block.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/__pycache__/block.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6280ca886b5bd7209955dfaeb96c5d9f73772d8e Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/__pycache__/block.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/__pycache__/context.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/__pycache__/context.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6d1fd77f7df824001299be011d8f5f0d54b084bd Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/__pycache__/context.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/__pycache__/exceptions.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/__pycache__/exceptions.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..4db3c375e71351f0df6d4c96a86a7e207cd7faf2 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/__pycache__/exceptions.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/__pycache__/grouped_data.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/__pycache__/grouped_data.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..26f77a28668f013bd89c86b1160786154df863b9 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/__pycache__/grouped_data.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/__pycache__/iterator.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/__pycache__/iterator.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9e51fba58ffebb744c6ee911634bec5fc2dd778d Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/__pycache__/iterator.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/__pycache__/preprocessor.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/__pycache__/preprocessor.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1b73623703bcbcd9d33ab8f6b144b14cd27a161a Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/__pycache__/preprocessor.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/arrow_ops/transform_pyarrow.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/arrow_ops/transform_pyarrow.py new file mode 100644 index 0000000000000000000000000000000000000000..a71a1eae6f61fe962cda9ddcccf6e400ab9c7623 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/arrow_ops/transform_pyarrow.py @@ -0,0 +1,497 @@ +from typing import TYPE_CHECKING, List, Union + +import numpy as np +from packaging.version import parse as parse_version + +from ray._private.utils import _get_pyarrow_version +from ray.air.util.tensor_extensions.arrow import ( + INT32_OVERFLOW_THRESHOLD, + MIN_PYARROW_VERSION_CHUNKED_ARRAY_TO_NUMPY_ZERO_COPY_ONLY, + PYARROW_VERSION, +) + +try: + import pyarrow +except ImportError: + pyarrow = None + + +if TYPE_CHECKING: + from ray.data._internal.planner.exchange.sort_task_spec import SortKey + + +def sort(table: "pyarrow.Table", sort_key: "SortKey") -> "pyarrow.Table": + import pyarrow.compute as pac + + indices = pac.sort_indices(table, sort_keys=sort_key.to_arrow_sort_args()) + return take_table(table, indices) + + +def take_table( + table: "pyarrow.Table", + indices: Union[List[int], "pyarrow.Array", "pyarrow.ChunkedArray"], +) -> "pyarrow.Table": + """Select rows from the table. + + This method is an alternative to pyarrow.Table.take(), which breaks for + extension arrays. This is exposed as a static method for easier use on + intermediate tables, not underlying an ArrowBlockAccessor. + """ + from ray.air.util.transform_pyarrow import ( + _concatenate_extension_column, + _is_column_extension_type, + ) + + if any(_is_column_extension_type(col) for col in table.columns): + new_cols = [] + for col in table.columns: + if _is_column_extension_type(col) and col.num_chunks > 1: + # .take() will concatenate internally, which currently breaks for + # extension arrays. + col = _concatenate_extension_column(col) + new_cols.append(col.take(indices)) + table = pyarrow.Table.from_arrays(new_cols, schema=table.schema) + else: + table = table.take(indices) + return table + + +def unify_schemas( + schemas: List["pyarrow.Schema"], +) -> "pyarrow.Schema": + """Version of `pyarrow.unify_schemas()` which also handles checks for + variable-shaped tensors in the given schemas. + + This function scans all input schemas to identify columns that contain + variable-shaped tensors or objects. For tensor columns, it ensures the + use of appropriate tensor types (including variable-shaped tensor types). + For object columns, it uses a specific object type to accommodate any + objects present. Additionally, it handles columns with null-typed lists + by determining their actual types from the given schemas. + + Currently, it disallows the concatenation of tensor columns and + pickled object columsn for performance reasons. + """ + import pyarrow as pa + + from ray.air.util.object_extensions.arrow import ArrowPythonObjectType + from ray.air.util.tensor_extensions.arrow import ( + ArrowTensorType, + ArrowVariableShapedTensorType, + ) + + schemas_to_unify = [] + schema_field_overrides = {} + + # Rollup columns with opaque (null-typed) lists, to override types in + # the following for-loop. + cols_with_null_list = set() + + all_columns = set() + for schema in schemas: + for col_name in schema.names: + col_type = schema.field(col_name).type + if pa.types.is_list(col_type) and pa.types.is_null(col_type.value_type): + cols_with_null_list.add(col_name) + all_columns.add(col_name) + + from ray.air.util.tensor_extensions.arrow import ( + get_arrow_extension_fixed_shape_tensor_types, + get_arrow_extension_tensor_types, + ) + + arrow_tensor_types = get_arrow_extension_tensor_types() + arrow_fixed_shape_tensor_types = get_arrow_extension_fixed_shape_tensor_types() + + columns_with_objects = set() + columns_with_tensor_array = set() + for col_name in all_columns: + for s in schemas: + indices = s.get_all_field_indices(col_name) + if len(indices) > 1: + # This is broken for Pandas blocks and broken with the logic here + raise ValueError( + f"Schema {s} has multiple fields with the same name: {col_name}" + ) + elif len(indices) == 0: + continue + if isinstance(s.field(col_name).type, ArrowPythonObjectType): + columns_with_objects.add(col_name) + if isinstance(s.field(col_name).type, arrow_tensor_types): + columns_with_tensor_array.add(col_name) + + if len(columns_with_objects.intersection(columns_with_tensor_array)) > 0: + # This is supportable if we use object type, but it will be expensive + raise ValueError( + "Found columns with both objects and tensors: " + f"{columns_with_tensor_array.intersection(columns_with_objects)}" + ) + for col_name in columns_with_tensor_array: + tensor_array_types = [ + s.field(col_name).type + for s in schemas + if isinstance(s.field(col_name).type, arrow_tensor_types) + ] + + if ArrowTensorType._need_variable_shaped_tensor_array(tensor_array_types): + if isinstance(tensor_array_types[0], ArrowVariableShapedTensorType): + new_type = tensor_array_types[0] + elif isinstance(tensor_array_types[0], arrow_fixed_shape_tensor_types): + new_type = ArrowVariableShapedTensorType( + dtype=tensor_array_types[0].scalar_type, + ndim=len(tensor_array_types[0].shape), + ) + else: + raise ValueError( + "Detected need for variable shaped tensor representation, " + f"but schema is not ArrayTensorType: {tensor_array_types[0]}" + ) + schema_field_overrides[col_name] = new_type + + for col_name in columns_with_objects: + schema_field_overrides[col_name] = ArrowPythonObjectType() + + if cols_with_null_list: + # For each opaque list column, iterate through all schemas until we find + # a valid value_type that can be used to override the column types in + # the following for-loop. + for col_name in cols_with_null_list: + for schema in schemas: + col_type = schema.field(col_name).type + if not pa.types.is_list(col_type) or not pa.types.is_null( + col_type.value_type + ): + schema_field_overrides[col_name] = col_type + break + + if schema_field_overrides: + # Go through all schemas and update the types of columns from the above loop. + for schema in schemas: + for col_name, col_new_type in schema_field_overrides.items(): + var_shaped_col = schema.field(col_name).with_type(col_new_type) + col_idx = schema.get_field_index(col_name) + schema = schema.set(col_idx, var_shaped_col) + schemas_to_unify.append(schema) + else: + schemas_to_unify = schemas + # Let Arrow unify the schema of non-tensor extension type columns. + return pyarrow.unify_schemas(schemas_to_unify) + + +def _concatenate_chunked_arrays(arrs: "pyarrow.ChunkedArray") -> "pyarrow.ChunkedArray": + """ + Concatenate provided chunked arrays into a single chunked array. + """ + from ray.data.extensions import get_arrow_extension_tensor_types + + tensor_types = get_arrow_extension_tensor_types() + + # Single flat list of chunks across all chunked arrays. + chunks = [] + type_ = None + for arr in arrs: + if type_ is None: + type_ = arr.type + else: + if isinstance(type_, tensor_types): + raise ValueError( + "_concatenate_chunked_arrays should only be used on non-tensor " + f"extension types, but got a chunked array of type {type_}." + ) + assert type_ == arr.type, f"Types mismatch: {type_} != {arr.type}" + # Add chunks for this chunked array to flat chunk list. + chunks.extend(arr.chunks) + # Construct chunked array on flat list of chunks. + return pyarrow.chunked_array(chunks, type=type_) + + +def concat(blocks: List["pyarrow.Table"]) -> "pyarrow.Table": + """Concatenate provided Arrow Tables into a single Arrow Table. This has special + handling for extension types that pyarrow.concat_tables does not yet support. + """ + import pyarrow as pa + + from ray.air.util.tensor_extensions.arrow import ArrowConversionError + from ray.data.extensions import ( + ArrowPythonObjectArray, + ArrowPythonObjectType, + ArrowTensorArray, + get_arrow_extension_tensor_types, + ) + + tensor_types = get_arrow_extension_tensor_types() + + if not blocks: + # Short-circuit on empty list of blocks. + return blocks + + if len(blocks) == 1: + return blocks[0] + + # Rollup columns with opaque (null-typed) lists, to process in following for-loop. + cols_with_null_list = set() + for b in blocks: + for col_name in b.schema.names: + col_type = b.schema.field(col_name).type + if pa.types.is_list(col_type) and pa.types.is_null(col_type.value_type): + cols_with_null_list.add(col_name) + + # If the result contains pyarrow schemas, unify them + schemas_to_unify = [b.schema for b in blocks] + try: + schema = unify_schemas(schemas_to_unify) + except Exception as e: + raise ArrowConversionError(str(blocks)) from e + + if ( + any(isinstance(type_, pa.ExtensionType) for type_ in schema.types) + or cols_with_null_list + ): + # Custom handling for extension array columns. + cols = [] + for col_name in schema.names: + col_chunked_arrays = [] + for block in blocks: + col_chunked_arrays.append(block.column(col_name)) + + if isinstance(schema.field(col_name).type, tensor_types): + # For our tensor extension types, manually construct a chunked array + # containing chunks from all blocks. This is to handle + # homogeneous-shaped block columns having different shapes across + # blocks: if tensor element shapes differ across blocks, a + # variable-shaped tensor array will be returned. + col = ArrowTensorArray._chunk_tensor_arrays( + [chunk for ca in col_chunked_arrays for chunk in ca.chunks] + ) + elif isinstance(schema.field(col_name).type, ArrowPythonObjectType): + chunks_to_concat = [] + # Cast everything to objects if concatenated with an object column + for ca in col_chunked_arrays: + for chunk in ca.chunks: + if isinstance(ca.type, ArrowPythonObjectType): + chunks_to_concat.append(chunk) + else: + chunks_to_concat.append( + ArrowPythonObjectArray.from_objects(chunk.to_pylist()) + ) + col = pa.chunked_array(chunks_to_concat) + else: + if col_name in cols_with_null_list: + # For each opaque list column, iterate through all schemas until + # we find a valid value_type that can be used to override the + # column types in the following for-loop. + scalar_type = None + for arr in col_chunked_arrays: + if not pa.types.is_list(arr.type) or not pa.types.is_null( + arr.type.value_type + ): + scalar_type = arr.type + break + + if scalar_type is not None: + for c_idx in range(len(col_chunked_arrays)): + c = col_chunked_arrays[c_idx] + if pa.types.is_list(c.type) and pa.types.is_null( + c.type.value_type + ): + if pa.types.is_list(scalar_type): + # If we are dealing with a list input, + # cast the array to the scalar_type found above. + col_chunked_arrays[c_idx] = c.cast(scalar_type) + else: + # If we are dealing with a single value, construct + # a new array with null values filled. + col_chunked_arrays[c_idx] = pa.chunked_array( + [pa.nulls(c.length(), type=scalar_type)] + ) + + col = _concatenate_chunked_arrays(col_chunked_arrays) + cols.append(col) + + # Build the concatenated table. + table = pyarrow.Table.from_arrays(cols, schema=schema) + # Validate table schema (this is a cheap check by default). + table.validate() + else: + # No extension array columns, so use built-in pyarrow.concat_tables. + if parse_version(_get_pyarrow_version()) >= parse_version("14.0.0"): + # `promote` was superseded by `promote_options='default'` in Arrow 14. To + # prevent `FutureWarning`s, we manually check the Arrow version and use the + # appropriate parameter. + table = pyarrow.concat_tables(blocks, promote_options="default") + else: + table = pyarrow.concat_tables(blocks, promote=True) + return table + + +def concat_and_sort( + blocks: List["pyarrow.Table"], sort_key: "SortKey" +) -> "pyarrow.Table": + import pyarrow.compute as pac + + ret = concat(blocks) + indices = pac.sort_indices(ret, sort_keys=sort_key.to_arrow_sort_args()) + return take_table(ret, indices) + + +def to_numpy( + array: Union["pyarrow.Array", "pyarrow.ChunkedArray"], + *, + zero_copy_only: bool = True, +) -> np.ndarray: + """Wrapper for `Array`s and `ChunkedArray`s `to_numpy` API, + handling API divergence b/w Arrow versions""" + + import pyarrow as pa + + if isinstance(array, pa.Array): + return array.to_numpy(zero_copy_only=zero_copy_only) + elif isinstance(array, pa.ChunkedArray): + if PYARROW_VERSION >= MIN_PYARROW_VERSION_CHUNKED_ARRAY_TO_NUMPY_ZERO_COPY_ONLY: + return array.to_numpy(zero_copy_only=zero_copy_only) + else: + return array.to_numpy() + else: + raise ValueError( + f"Either of `Array` or `ChunkedArray` was expected, got {type(array)}" + ) + + +def combine_chunks(table: "pyarrow.Table") -> "pyarrow.Table": + """This is counterpart for Pyarrow's `Table.combine_chunks` that's using + extended `ChunkedArray` combination protocol. + + For more details check out `combine_chunked_array` py-doc + """ + + new_column_values_arrays = [] + + for col in table.columns: + new_column_values_arrays.append(combine_chunked_array(col)) + + return pyarrow.Table.from_arrays(new_column_values_arrays, schema=table.schema) + + +def combine_chunked_array( + array: "pyarrow.ChunkedArray", +) -> Union["pyarrow.Array", "pyarrow.ChunkedArray"]: + """This is counterpart for Pyarrow's `ChunkedArray.combine_chunks` that additionally + + 1. Handles `ExtensionType`s (like ArrowTensorType, ArrowTensorTypeV2, + ArrowPythonObjectType, etc) + + 2. Making sure `ChunkedArray`s comprising provided `Table` are combined + safely, ie avoiding overflows of Arrow's internal offsets (using int32 for + most of its native types, other than "large" kind). + + For more details check py-doc of `_try_combine_chunks_safe` method. + """ + + import pyarrow as pa + + from ray.air.util.transform_pyarrow import ( + _concatenate_extension_column, + _is_column_extension_type, + ) + + assert isinstance( + array, pa.ChunkedArray + ), f"Expected `ChunkedArray`, got {type(array)}" + + if _is_column_extension_type(array): + # Arrow `ExtensionArray`s can't be concatenated via `combine_chunks`, + # hence require manual concatenation + return _concatenate_extension_column(array) + elif len(array.chunks) == 0: + # NOTE: In case there's no chunks, we need to explicitly create + # an empty array since calling into `combine_chunks` would fail + # due to it expecting at least 1 chunk to be present + return pa.array([], type=array.type) + else: + return _try_combine_chunks_safe(array) + + +def _try_combine_chunks_safe( + array: "pyarrow.ChunkedArray", max_chunk_size=INT32_OVERFLOW_THRESHOLD +) -> Union["pyarrow.Array", "pyarrow.ChunkedArray"]: + """This method provides a safe way of combining `ChunkedArray`s exceeding 2 GiB + in size, which aren't using "large_*" types (and therefore relying on int32 + offsets). + + When handling provided `ChunkedArray` this method will be either + + - Relying on PyArrow's default `combine_chunks` (therefore returning single + contiguous `Array`) in cases when + - Array's total size is < 2 GiB + - Array's underlying type is of "large" kind (ie using one of the + `large_*` type family) + - Safely combining subsets of tasks such that resulting `Array`s to not + exceed 2 GiB in size (therefore returning another `ChunkedArray` albeit + with potentially smaller number of chunks that have resulted from clumping + the original ones) + + Returns: + - pa.Array if it's possible to combine provided pa.ChunkedArray into single + contiguous array + - pa.ChunkedArray (albeit with chunks re-combined) if it's not possible to + produce single pa.Array + """ + + import pyarrow as pa + + from ray.air.util.transform_pyarrow import _is_column_extension_type + + assert not _is_column_extension_type( + array + ), f"Arrow `ExtensionType`s are not accepted (got {array.type})" + + int64_type_predicates = [ + pa.types.is_large_list, + pa.types.is_large_string, + pa.types.is_large_binary, + pa.types.is_large_unicode, + ] + + if array.nbytes < max_chunk_size or any( + p(array.type) for p in int64_type_predicates + ): + # It's safe to combine provided `ChunkedArray` in either of 2 cases: + # - It's cumulative size is < 2 GiB + # - It's of 'large' kind (ie one using int64 offsets internally) + return array.combine_chunks() + + # In this case it's actually *NOT* safe to try to directly combine + # Arrow's `ChunkedArray` and is impossible to produce single, contiguous + # `Array` since + # - It's estimated to hold > 2 GiB + # - Its type is not of the "large" kind (and hence is using int32 + # offsets internally, which would overflow) + # + # In this case instead of combining into single contiguous array, we + # instead just "clump" existing chunks into bigger ones, but no bigger + # than 2 GiB each. + # + # NOTE: This branch actually returns `ChunkedArray` and not an `Array` + + # To stay under 2 GiB limit we are slicing provided list of chunks into + # slices no larger than 2 GiB (as compared to just directly using `concat_arrays`) + slices = [] + + cur_slice_start = 0 + cur_slice_size_bytes = 0 + + for i, chunk in enumerate(array.chunks): + chunk_size = chunk.nbytes + + if cur_slice_size_bytes + chunk_size > max_chunk_size: + slices.append(array.chunks[cur_slice_start:i]) + + cur_slice_start = i + cur_slice_size_bytes = 0 + + cur_slice_size_bytes += chunk_size + + # Add remaining chunks as last slice + slices.append(array.chunks[cur_slice_start:]) + + return pa.chunked_array([pa.concat_arrays(s) for s in slices]) diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/datasource/__pycache__/__init__.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/datasource/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a599e8cd1bc94327ccee80e01e7087de6e536b79 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/datasource/__pycache__/__init__.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/datasource/__pycache__/hudi_datasource.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/datasource/__pycache__/hudi_datasource.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0ef13830a2f923f47bef63fbca98b4f71622ff7b Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/datasource/__pycache__/hudi_datasource.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/datasource/__pycache__/webdataset_datasink.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/datasource/__pycache__/webdataset_datasink.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..95b1b67db0798224b47ccb23dd4eabd3bcc87d19 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/datasource/__pycache__/webdataset_datasink.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/__pycache__/__init__.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7c2beffc50663b4e1bb7df0b4aa2b8a92e18812a Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/__pycache__/__init__.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/__pycache__/optimizers.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/__pycache__/optimizers.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..de37e98e836a736f00a796e6eba7250f19b4f468 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/__pycache__/optimizers.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/__pycache__/util.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/__pycache__/util.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..1ab97f92e892b65ad7000ac9cd953bade7b895c4 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/__pycache__/util.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/__init__.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..644082d6341d9167df42479f74ca6cc6200272dc Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/__init__.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/logical_operator.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/logical_operator.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8231eda57c4b452de42e53f3476d3222b2155c97 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/logical_operator.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/logical_plan.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/logical_plan.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7bb42d17142b767f1a7130f8d8ea6b58fa171379 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/logical_plan.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/operator.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/operator.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..0b074b9464f0908805ee57acb6cd4f5b3f4111d0 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/operator.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/optimizer.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/optimizer.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9c83cc0d6f0b068d7efc09b02b0fb66a048db1f7 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/optimizer.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/physical_plan.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/physical_plan.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..386591bf9c9ae1195392a9da9b50f9a38b6ab7ac Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/physical_plan.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/plan.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/plan.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e635f1adfc8dd3553d97e9243b051fec0c8f9575 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/__pycache__/plan.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/logical_operator.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/logical_operator.py new file mode 100644 index 0000000000000000000000000000000000000000..84535706cd5080061b88aa675944dc80dcdc32bb --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/logical_operator.py @@ -0,0 +1,79 @@ +from typing import TYPE_CHECKING, Iterator, List, Optional + +from .operator import Operator +from ray.data.block import BlockMetadata + +if TYPE_CHECKING: + from ray.data._internal.execution.interfaces import RefBundle + + +class LogicalOperator(Operator): + """Abstract class for logical operators. + + A logical operator describes transformation, and later is converted into + physical operator. + """ + + def __init__( + self, + name: str, + input_dependencies: List["LogicalOperator"], + num_outputs: Optional[int] = None, + ): + super().__init__( + name, + input_dependencies, + ) + for x in input_dependencies: + assert isinstance(x, LogicalOperator), x + self._num_outputs = num_outputs + + def estimated_num_outputs(self) -> Optional[int]: + """Returns the estimated number of blocks that + would be outputted by this logical operator. + + This method does not execute the plan, so it does not take into consideration + block splitting. This method only considers high-level block constraints like + `Dataset.repartition(num_blocks=X)`. A more accurate estimation can be given by + `PhysicalOperator.num_outputs_total()` during execution. + """ + if self._num_outputs is not None: + return self._num_outputs + elif len(self._input_dependencies) == 1: + return self._input_dependencies[0].estimated_num_outputs() + return None + + # Override the following 3 methods to correct type hints. + + @property + def input_dependencies(self) -> List["LogicalOperator"]: + return super().input_dependencies # type: ignore + + @property + def output_dependencies(self) -> List["LogicalOperator"]: + return super().output_dependencies # type: ignore + + def post_order_iter(self) -> Iterator["LogicalOperator"]: + return super().post_order_iter() # type: ignore + + def output_data(self) -> Optional[List["RefBundle"]]: + """The output data of this operator, or ``None`` if not known.""" + return None + + def aggregate_output_metadata(self) -> BlockMetadata: + """A ``BlockMetadata`` that represents the aggregate metadata of the outputs. + + This method is used by methods like :meth:`~ray.data.Dataset.schema` to + efficiently return metadata. + """ + return BlockMetadata(None, None, None, None, None) + + def is_lineage_serializable(self) -> bool: + """Returns whether the lineage of this operator can be serialized. + + An operator is lineage serializable if you can serialize it on one machine and + deserialize it on another without losing information. Operators that store + object references (e.g., ``InputData``) aren't lineage serializable because the + objects aren't available on the deserialized machine. + """ + return True diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/logical_plan.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/logical_plan.py new file mode 100644 index 0000000000000000000000000000000000000000..3e0196bb440bbdb02ff2b112e2b68d8d2be58088 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/logical_plan.py @@ -0,0 +1,31 @@ +from typing import TYPE_CHECKING, List + +from .logical_operator import LogicalOperator +from .plan import Plan + +if TYPE_CHECKING: + from ray.data import DataContext + + +class LogicalPlan(Plan): + """The plan with a DAG of logical operators.""" + + def __init__(self, dag: LogicalOperator, context: "DataContext"): + super().__init__(context) + self._dag = dag + + @property + def dag(self) -> LogicalOperator: + """Get the DAG of logical operators.""" + return self._dag + + def sources(self) -> List[LogicalOperator]: + """List of operators that are sources for this plan's DAG.""" + # If an operator has no input dependencies, it's a source. + if not any(self._dag.input_dependencies): + return [self._dag] + + sources = [] + for op in self._dag.input_dependencies: + sources.extend(LogicalPlan(op, self._context).sources()) + return sources diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/operator.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/operator.py new file mode 100644 index 0000000000000000000000000000000000000000..76a320ef815a23cb319146221d32c7be10e5be52 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/operator.py @@ -0,0 +1,58 @@ +from typing import Iterator, List + + +class Operator: + """Abstract class for operators. + + Operators live on the driver side of the Dataset only. + """ + + def __init__( + self, + name: str, + input_dependencies: List["Operator"], + ): + self._name = name + self._input_dependencies = input_dependencies + self._output_dependencies = [] + for x in input_dependencies: + assert isinstance(x, Operator), x + x._output_dependencies.append(self) + + @property + def name(self) -> str: + return self._name + + @property + def input_dependencies(self) -> List["Operator"]: + """List of operators that provide inputs for this operator.""" + assert hasattr( + self, "_input_dependencies" + ), "Operator.__init__() was not called." + return self._input_dependencies + + @property + def output_dependencies(self) -> List["Operator"]: + """List of operators that consume outputs from this operator.""" + assert hasattr( + self, "_output_dependencies" + ), "Operator.__init__() was not called." + return self._output_dependencies + + def post_order_iter(self) -> Iterator["Operator"]: + """Depth-first traversal of this operator and its input dependencies.""" + for op in self.input_dependencies: + yield from op.post_order_iter() + yield self + + def __repr__(self) -> str: + if self.input_dependencies: + out_str = ", ".join([str(x) for x in self.input_dependencies]) + out_str += " -> " + else: + out_str = "" + out_str += f"{self.__class__.__name__}[{self._name}]" + return out_str + + def __str__(self) -> str: + return repr(self) diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/optimizer.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/optimizer.py new file mode 100644 index 0000000000000000000000000000000000000000..6a25a44afe624b2e3ad6182739f68ed59b5cf720 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/optimizer.py @@ -0,0 +1,29 @@ +from typing import List + +from .plan import Plan + + +class Rule: + """Abstract class for optimization rule.""" + + def apply(self, plan: Plan) -> Plan: + """Apply the optimization rule to the execution plan.""" + raise NotImplementedError + + +class Optimizer: + """Abstract class for optimizers. + + An optimizers transforms a DAG of operators with a list of predefined rules. + """ + + @property + def rules(self) -> List[Rule]: + """List of predefined rules for this optimizer.""" + raise NotImplementedError + + def optimize(self, plan: Plan) -> Plan: + """Optimize operators with a list of rules.""" + for rule in self.rules: + plan = rule.apply(plan) + return plan diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/physical_plan.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/physical_plan.py new file mode 100644 index 0000000000000000000000000000000000000000..29503831db85e7d87f1f044d7c910826fa970515 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/interfaces/physical_plan.py @@ -0,0 +1,34 @@ +from typing import TYPE_CHECKING, Dict + +from .logical_operator import LogicalOperator +from .plan import Plan + +if TYPE_CHECKING: + from ray.data import DataContext + from ray.data._internal.execution.interfaces import PhysicalOperator + + +class PhysicalPlan(Plan): + """The plan with a DAG of physical operators.""" + + def __init__( + self, + dag: "PhysicalOperator", + op_map: Dict["PhysicalOperator", LogicalOperator], + context: "DataContext", + ): + super().__init__(context) + self._dag = dag + self._op_map = op_map + + @property + def dag(self) -> "PhysicalOperator": + """Get the DAG of physical operators.""" + return self._dag + + @property + def op_map(self) -> Dict["PhysicalOperator", LogicalOperator]: + """ + Get a mapping from physical operators to their corresponding logical operator. + """ + return self._op_map diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__init__.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/__init__.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..dc2a1a86d064509514c44f333eef5071f067e70a Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/__init__.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/all_to_all_operator.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/all_to_all_operator.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7a81c852b765626f582f73a63d593269cd6345c1 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/all_to_all_operator.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/count_operator.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/count_operator.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e3e432cfdf60330c007aa737f4af4558220e484f Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/count_operator.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/from_operators.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/from_operators.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..090bf13f16421ebfd1ef453875ae7ff031c945e1 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/from_operators.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/input_data_operator.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/input_data_operator.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a2a6df6a2d03aded93e728bc86dff9234b57ceea Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/input_data_operator.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/map_operator.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/map_operator.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8d2dacc19bb5552add085b76e6ec6ca4e7265e6d Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/map_operator.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/n_ary_operator.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/n_ary_operator.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9a8401f61b1bbc4599d714e7b4458aeb1eeb150a Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/n_ary_operator.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/one_to_one_operator.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/one_to_one_operator.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c24b7806f960bf307f57aa04a86fb5648b1542ec Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/one_to_one_operator.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/read_operator.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/read_operator.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..6e78ea604c69a36b914283fe1d1475c93fcbcbdd Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/read_operator.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/write_operator.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/write_operator.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..058b3d2de938efd62e10258c33e586f1ad3d6342 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/__pycache__/write_operator.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/all_to_all_operator.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/all_to_all_operator.py new file mode 100644 index 0000000000000000000000000000000000000000..745103f0036fee1de56fcd0ef645aac438af33d6 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/all_to_all_operator.py @@ -0,0 +1,163 @@ +from typing import Any, Dict, List, Optional + +from ray.data._internal.logical.interfaces import LogicalOperator +from ray.data._internal.planner.exchange.interfaces import ExchangeTaskSpec +from ray.data._internal.planner.exchange.shuffle_task_spec import ShuffleTaskSpec +from ray.data._internal.planner.exchange.sort_task_spec import SortKey, SortTaskSpec +from ray.data.aggregate import AggregateFn +from ray.data.block import BlockMetadata + + +class AbstractAllToAll(LogicalOperator): + """Abstract class for logical operators should be converted to physical + AllToAllOperator. + """ + + def __init__( + self, + name: str, + input_op: LogicalOperator, + num_outputs: Optional[int] = None, + sub_progress_bar_names: Optional[List[str]] = None, + ray_remote_args: Optional[Dict[str, Any]] = None, + ): + """ + Args: + name: Name for this operator. This is the name that will appear when + inspecting the logical plan of a Dataset. + input_op: The operator preceding this operator in the plan DAG. The outputs + of `input_op` will be the inputs to this operator. + num_outputs: The number of expected output bundles outputted by this + operator. + ray_remote_args: Args to provide to ray.remote. + """ + super().__init__(name, [input_op], num_outputs) + self._num_outputs = num_outputs + self._ray_remote_args = ray_remote_args or {} + self._sub_progress_bar_names = sub_progress_bar_names + + +class RandomizeBlocks(AbstractAllToAll): + """Logical operator for randomize_block_order.""" + + def __init__( + self, + input_op: LogicalOperator, + seed: Optional[int] = None, + ): + super().__init__( + "RandomizeBlockOrder", + input_op, + ) + self._seed = seed + + def aggregate_output_metadata(self) -> BlockMetadata: + assert len(self._input_dependencies) == 1, len(self._input_dependencies) + return self._input_dependencies[0].aggregate_output_metadata() + + +class RandomShuffle(AbstractAllToAll): + """Logical operator for random_shuffle.""" + + def __init__( + self, + input_op: LogicalOperator, + name: str = "RandomShuffle", + seed: Optional[int] = None, + ray_remote_args: Optional[Dict[str, Any]] = None, + ): + super().__init__( + name, + input_op, + sub_progress_bar_names=[ + ExchangeTaskSpec.MAP_SUB_PROGRESS_BAR_NAME, + ExchangeTaskSpec.REDUCE_SUB_PROGRESS_BAR_NAME, + ], + ray_remote_args=ray_remote_args, + ) + self._seed = seed + + def aggregate_output_metadata(self) -> BlockMetadata: + assert len(self._input_dependencies) == 1, len(self._input_dependencies) + return self._input_dependencies[0].aggregate_output_metadata() + + +class Repartition(AbstractAllToAll): + """Logical operator for repartition.""" + + def __init__( + self, + input_op: LogicalOperator, + num_outputs: int, + shuffle: bool, + ): + if shuffle: + sub_progress_bar_names = [ + ExchangeTaskSpec.MAP_SUB_PROGRESS_BAR_NAME, + ExchangeTaskSpec.REDUCE_SUB_PROGRESS_BAR_NAME, + ] + else: + sub_progress_bar_names = [ + ShuffleTaskSpec.SPLIT_REPARTITION_SUB_PROGRESS_BAR_NAME, + ] + super().__init__( + "Repartition", + input_op, + num_outputs=num_outputs, + sub_progress_bar_names=sub_progress_bar_names, + ) + self._shuffle = shuffle + + def aggregate_output_metadata(self) -> BlockMetadata: + assert len(self._input_dependencies) == 1, len(self._input_dependencies) + return self._input_dependencies[0].aggregate_output_metadata() + + +class Sort(AbstractAllToAll): + """Logical operator for sort.""" + + def __init__( + self, + input_op: LogicalOperator, + sort_key: SortKey, + batch_format: Optional[str] = "default", + ): + super().__init__( + "Sort", + input_op, + sub_progress_bar_names=[ + SortTaskSpec.SORT_SAMPLE_SUB_PROGRESS_BAR_NAME, + ExchangeTaskSpec.MAP_SUB_PROGRESS_BAR_NAME, + ExchangeTaskSpec.REDUCE_SUB_PROGRESS_BAR_NAME, + ], + ) + self._sort_key = sort_key + self._batch_format = batch_format + + def aggregate_output_metadata(self) -> BlockMetadata: + assert len(self._input_dependencies) == 1, len(self._input_dependencies) + return self._input_dependencies[0].aggregate_output_metadata() + + +class Aggregate(AbstractAllToAll): + """Logical operator for aggregate.""" + + def __init__( + self, + input_op: LogicalOperator, + key: Optional[str], + aggs: List[AggregateFn], + batch_format: Optional[str] = "default", + ): + super().__init__( + "Aggregate", + input_op, + sub_progress_bar_names=[ + SortTaskSpec.SORT_SAMPLE_SUB_PROGRESS_BAR_NAME, + ExchangeTaskSpec.MAP_SUB_PROGRESS_BAR_NAME, + ExchangeTaskSpec.REDUCE_SUB_PROGRESS_BAR_NAME, + ], + ) + self._key = key + self._aggs = aggs + self._batch_format = batch_format diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/count_operator.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/count_operator.py new file mode 100644 index 0000000000000000000000000000000000000000..409c99e3c000698622be3f6294d419d1c59ff2d8 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/count_operator.py @@ -0,0 +1,20 @@ +from typing import List + +from ray.data._internal.logical.interfaces import LogicalOperator + + +class Count(LogicalOperator): + """Logical operator that represents counting the number of rows in inputs. + + Physical operators that implement this logical operator should produce one or more + rows with a single column named `Count.COLUMN_NAME`. When you sum the values in + this column, you should get the total number of rows in the dataset. + """ + + COLUMN_NAME = "__num_rows" + + def __init__( + self, + input_dependencies: List["LogicalOperator"], + ): + super().__init__("Count", input_dependencies) diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/from_operators.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/from_operators.py new file mode 100644 index 0000000000000000000000000000000000000000..afe5e8200bb14040e712e4b2faef12e79516f8df --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/from_operators.py @@ -0,0 +1,105 @@ +import abc +import functools +from typing import TYPE_CHECKING, List, Optional, Union + +from ray.data._internal.execution.interfaces import RefBundle +from ray.data._internal.logical.interfaces import LogicalOperator +from ray.data._internal.util import unify_block_metadata_schema +from ray.data.block import Block, BlockMetadata +from ray.types import ObjectRef + +if TYPE_CHECKING: + import pyarrow as pa + + ArrowTable = Union["pa.Table", bytes] + + +class AbstractFrom(LogicalOperator, metaclass=abc.ABCMeta): + """Abstract logical operator for `from_*`.""" + + def __init__( + self, + input_blocks: List[ObjectRef[Block]], + input_metadata: List[BlockMetadata], + ): + super().__init__(self.__class__.__name__, [], len(input_blocks)) + assert len(input_blocks) == len(input_metadata), ( + len(input_blocks), + len(input_metadata), + ) + # `owns_blocks` is False because this op may be shared by multiple Datasets. + self._input_data = [ + RefBundle([(input_blocks[i], input_metadata[i])], owns_blocks=False) + for i in range(len(input_blocks)) + ] + + @property + def input_data(self) -> List[RefBundle]: + return self._input_data + + def output_data(self) -> Optional[List[RefBundle]]: + return self._input_data + + def aggregate_output_metadata(self) -> BlockMetadata: + return self._cached_output_metadata + + @functools.cached_property + def _cached_output_metadata(self) -> BlockMetadata: + return BlockMetadata( + num_rows=self._num_rows(), + size_bytes=self._size_bytes(), + schema=self._schema(), + input_files=None, + exec_stats=None, + ) + + def _num_rows(self): + if all(bundle.num_rows() is not None for bundle in self._input_data): + return sum(bundle.num_rows() for bundle in self._input_data) + else: + return None + + def _size_bytes(self): + metadata = [m for bundle in self._input_data for m in bundle.metadata] + if all(m.size_bytes is not None for m in metadata): + return sum(m.size_bytes for m in metadata) + else: + return None + + def _schema(self): + metadata = [m for bundle in self._input_data for m in bundle.metadata] + return unify_block_metadata_schema(metadata) + + def is_lineage_serializable(self) -> bool: + # This operator isn't serializable because it contains ObjectRefs. + return False + + +class FromItems(AbstractFrom): + """Logical operator for `from_items`.""" + + pass + + +class FromBlocks(AbstractFrom): + """Logical operator for `from_blocks`.""" + + pass + + +class FromNumpy(AbstractFrom): + """Logical operator for `from_numpy`.""" + + pass + + +class FromArrow(AbstractFrom): + """Logical operator for `from_arrow`.""" + + pass + + +class FromPandas(AbstractFrom): + """Logical operator for `from_pandas`.""" + + pass diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/input_data_operator.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/input_data_operator.py new file mode 100644 index 0000000000000000000000000000000000000000..2296b0ee315441bcdb0a3acd49791576aea3e191 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/input_data_operator.py @@ -0,0 +1,74 @@ +import functools +from typing import Callable, List, Optional + +from ray.data._internal.execution.interfaces import RefBundle +from ray.data._internal.logical.interfaces import LogicalOperator +from ray.data._internal.util import unify_block_metadata_schema +from ray.data.block import BlockMetadata + + +class InputData(LogicalOperator): + """Logical operator for input data. + + This may hold cached blocks from a previous Dataset execution, or + the arguments for read tasks. + """ + + def __init__( + self, + input_data: Optional[List[RefBundle]] = None, + input_data_factory: Optional[Callable[[int], List[RefBundle]]] = None, + ): + assert (input_data is None) != ( + input_data_factory is None + ), "Only one of input_data and input_data_factory should be set." + super().__init__( + "InputData", [], len(input_data) if input_data is not None else None + ) + self.input_data = input_data + self.input_data_factory = input_data_factory + + def output_data(self) -> Optional[List[RefBundle]]: + if self.input_data is None: + return None + return self.input_data + + def aggregate_output_metadata(self) -> BlockMetadata: + return self._cached_output_metadata + + @functools.cached_property + def _cached_output_metadata(self) -> BlockMetadata: + if self.input_data is None: + return BlockMetadata(None, None, None, None, None) + + return BlockMetadata( + num_rows=self._num_rows(), + size_bytes=self._size_bytes(), + schema=self._schema(), + input_files=None, + exec_stats=None, + ) + + def _num_rows(self): + assert self.input_data is not None + if all(bundle.num_rows() is not None for bundle in self.input_data): + return sum(bundle.num_rows() for bundle in self.input_data) + else: + return None + + def _size_bytes(self): + assert self.input_data is not None + metadata = [m for bundle in self.input_data for m in bundle.metadata] + if all(m.size_bytes is not None for m in metadata): + return sum(m.size_bytes for m in metadata) + else: + return None + + def _schema(self): + assert self.input_data is not None + metadata = [m for bundle in self.input_data for m in bundle.metadata] + return unify_block_metadata_schema(metadata) + + def is_lineage_serializable(self) -> bool: + # This operator isn't serializable because it contains ObjectRefs. + return False diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/map_operator.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/map_operator.py new file mode 100644 index 0000000000000000000000000000000000000000..fd7ad71e5a885bf512b08a247de4c51346ca9de5 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/map_operator.py @@ -0,0 +1,293 @@ +import inspect +import logging +from typing import Any, Callable, Dict, Iterable, List, Optional, Union + +from ray.data._internal.compute import ComputeStrategy, TaskPoolStrategy +from ray.data._internal.logical.interfaces import LogicalOperator +from ray.data._internal.logical.operators.one_to_one_operator import AbstractOneToOne +from ray.data.block import UserDefinedFunction +from ray.data.context import DEFAULT_BATCH_SIZE +from ray.data.preprocessor import Preprocessor + +logger = logging.getLogger(__name__) + + +class AbstractMap(AbstractOneToOne): + """Abstract class for logical operators that should be converted to physical + MapOperator. + """ + + def __init__( + self, + name: str, + input_op: Optional[LogicalOperator] = None, + num_outputs: Optional[int] = None, + *, + min_rows_per_bundled_input: Optional[int] = None, + ray_remote_args: Optional[Dict[str, Any]] = None, + ray_remote_args_fn: Optional[Callable[[], Dict[str, Any]]] = None, + ): + """ + Args: + name: Name for this operator. This is the name that will appear when + inspecting the logical plan of a Dataset. + input_op: The operator preceding this operator in the plan DAG. The outputs + of `input_op` will be the inputs to this operator. + min_rows_per_bundled_input: The target number of rows to pass to + ``MapOperator._add_bundled_input()``. + ray_remote_args: Args to provide to ray.remote. + ray_remote_args_fn: A function that returns a dictionary of remote args + passed to each map worker. The purpose of this argument is to generate + dynamic arguments for each actor/task, and will be called each time + prior to initializing the worker. Args returned from this dict will + always override the args in ``ray_remote_args``. Note: this is an + advanced, experimental feature. + """ + super().__init__(name, input_op, num_outputs) + self._min_rows_per_bundled_input = min_rows_per_bundled_input + self._ray_remote_args = ray_remote_args or {} + self._ray_remote_args_fn = ray_remote_args_fn + + +class AbstractUDFMap(AbstractMap): + """Abstract class for logical operators performing a UDF that should be converted + to physical MapOperator. + """ + + def __init__( + self, + name: str, + input_op: LogicalOperator, + fn: UserDefinedFunction, + fn_args: Optional[Iterable[Any]] = None, + fn_kwargs: Optional[Dict[str, Any]] = None, + fn_constructor_args: Optional[Iterable[Any]] = None, + fn_constructor_kwargs: Optional[Dict[str, Any]] = None, + min_rows_per_bundled_input: Optional[int] = None, + compute: Optional[Union[str, ComputeStrategy]] = None, + ray_remote_args_fn: Optional[Callable[[], Dict[str, Any]]] = None, + ray_remote_args: Optional[Dict[str, Any]] = None, + ): + """ + Args: + name: Name for this operator. This is the name that will appear when + inspecting the logical plan of a Dataset. + input_op: The operator preceding this operator in the plan DAG. The outputs + of `input_op` will be the inputs to this operator. + fn: User-defined function to be called. + fn_args: Arguments to `fn`. + fn_kwargs: Keyword arguments to `fn`. + fn_constructor_args: Arguments to provide to the initializor of `fn` if + `fn` is a callable class. + fn_constructor_kwargs: Keyword Arguments to provide to the initializor of + `fn` if `fn` is a callable class. + min_rows_per_bundled_input: The target number of rows to pass to + ``MapOperator._add_bundled_input()``. + compute: The compute strategy, either ``"tasks"`` (default) to use Ray + tasks, or ``"actors"`` to use an autoscaling actor pool. + ray_remote_args_fn: A function that returns a dictionary of remote args + passed to each map worker. The purpose of this argument is to generate + dynamic arguments for each actor/task, and will be called each time + prior to initializing the worker. Args returned from this dict will + always override the args in ``ray_remote_args``. Note: this is an + advanced, experimental feature. + ray_remote_args: Args to provide to ray.remote. + """ + name = self._get_operator_name(name, fn) + super().__init__( + name, + input_op, + min_rows_per_bundled_input=min_rows_per_bundled_input, + ray_remote_args=ray_remote_args, + ) + self._fn = fn + self._fn_args = fn_args + self._fn_kwargs = fn_kwargs + self._fn_constructor_args = fn_constructor_args + self._fn_constructor_kwargs = fn_constructor_kwargs + self._compute = compute or TaskPoolStrategy() + self._ray_remote_args_fn = ray_remote_args_fn + + def _get_operator_name(self, op_name: str, fn: UserDefinedFunction): + """Gets the Operator name including the map `fn` UDF name.""" + # If the input `fn` is a Preprocessor, the + # name is simply the name of the Preprocessor class. + if inspect.ismethod(fn) and isinstance(fn.__self__, Preprocessor): + return fn.__self__.__class__.__name__ + + # Otherwise, it takes the form of `()`, + # e.g. `MapBatches(my_udf)`. + try: + if inspect.isclass(fn): + # callable class + return f"{op_name}({fn.__name__})" + elif inspect.ismethod(fn): + # class method + return f"{op_name}({fn.__self__.__class__.__name__}.{fn.__name__})" + elif inspect.isfunction(fn): + # normal function or lambda function. + return f"{op_name}({fn.__name__})" + else: + # callable object. + return f"{op_name}({fn.__class__.__name__})" + except AttributeError as e: + logger.error("Failed to get name of UDF %s: %s", fn, e) + return "" + + +class MapBatches(AbstractUDFMap): + """Logical operator for map_batches.""" + + def __init__( + self, + input_op: LogicalOperator, + fn: UserDefinedFunction, + batch_size: Optional[int] = DEFAULT_BATCH_SIZE, + batch_format: str = "default", + zero_copy_batch: bool = False, + fn_args: Optional[Iterable[Any]] = None, + fn_kwargs: Optional[Dict[str, Any]] = None, + fn_constructor_args: Optional[Iterable[Any]] = None, + fn_constructor_kwargs: Optional[Dict[str, Any]] = None, + min_rows_per_bundled_input: Optional[int] = None, + compute: Optional[Union[str, ComputeStrategy]] = None, + ray_remote_args_fn: Optional[Callable[[], Dict[str, Any]]] = None, + ray_remote_args: Optional[Dict[str, Any]] = None, + ): + super().__init__( + "MapBatches", + input_op, + fn, + fn_args=fn_args, + fn_kwargs=fn_kwargs, + fn_constructor_args=fn_constructor_args, + fn_constructor_kwargs=fn_constructor_kwargs, + min_rows_per_bundled_input=min_rows_per_bundled_input, + compute=compute, + ray_remote_args_fn=ray_remote_args_fn, + ray_remote_args=ray_remote_args, + ) + self._batch_size = batch_size + self._batch_format = batch_format + self._zero_copy_batch = zero_copy_batch + + @property + def can_modify_num_rows(self) -> bool: + return False + + +class MapRows(AbstractUDFMap): + """Logical operator for map.""" + + def __init__( + self, + input_op: LogicalOperator, + fn: UserDefinedFunction, + fn_args: Optional[Iterable[Any]] = None, + fn_kwargs: Optional[Dict[str, Any]] = None, + fn_constructor_args: Optional[Iterable[Any]] = None, + fn_constructor_kwargs: Optional[Dict[str, Any]] = None, + compute: Optional[Union[str, ComputeStrategy]] = None, + ray_remote_args_fn: Optional[Callable[[], Dict[str, Any]]] = None, + ray_remote_args: Optional[Dict[str, Any]] = None, + ): + super().__init__( + "Map", + input_op, + fn, + fn_args=fn_args, + fn_kwargs=fn_kwargs, + fn_constructor_args=fn_constructor_args, + fn_constructor_kwargs=fn_constructor_kwargs, + compute=compute, + ray_remote_args_fn=ray_remote_args_fn, + ray_remote_args=ray_remote_args, + ) + + @property + def can_modify_num_rows(self) -> bool: + return False + + +class Filter(AbstractUDFMap): + """Logical operator for filter.""" + + def __init__( + self, + input_op: LogicalOperator, + fn: UserDefinedFunction, + compute: Optional[Union[str, ComputeStrategy]] = None, + ray_remote_args_fn: Optional[Callable[[], Dict[str, Any]]] = None, + ray_remote_args: Optional[Dict[str, Any]] = None, + ): + super().__init__( + "Filter", + input_op, + fn, + compute=compute, + ray_remote_args_fn=ray_remote_args_fn, + ray_remote_args=ray_remote_args, + ) + + @property + def can_modify_num_rows(self) -> bool: + return True + + +class Project(AbstractMap): + """Logical operator for select_columns.""" + + def __init__( + self, + input_op: LogicalOperator, + cols: List[str], + compute: Optional[Union[str, ComputeStrategy]] = None, + ray_remote_args: Optional[Dict[str, Any]] = None, + ): + super().__init__("Project", input_op=input_op, ray_remote_args=ray_remote_args) + self._compute = compute + self._batch_size = DEFAULT_BATCH_SIZE + self._cols = cols + self._batch_format = "pyarrow" + self._zero_copy_batch = True + + @property + def cols(self) -> List[str]: + return self._cols + + @property + def can_modify_num_rows(self) -> bool: + return False + + +class FlatMap(AbstractUDFMap): + """Logical operator for flat_map.""" + + def __init__( + self, + input_op: LogicalOperator, + fn: UserDefinedFunction, + fn_args: Optional[Iterable[Any]] = None, + fn_kwargs: Optional[Dict[str, Any]] = None, + fn_constructor_args: Optional[Iterable[Any]] = None, + fn_constructor_kwargs: Optional[Dict[str, Any]] = None, + compute: Optional[Union[str, ComputeStrategy]] = None, + ray_remote_args_fn: Optional[Callable[[], Dict[str, Any]]] = None, + ray_remote_args: Optional[Dict[str, Any]] = None, + ): + super().__init__( + "FlatMap", + input_op, + fn, + fn_args=fn_args, + fn_kwargs=fn_kwargs, + fn_constructor_args=fn_constructor_args, + fn_constructor_kwargs=fn_constructor_kwargs, + compute=compute, + ray_remote_args_fn=ray_remote_args_fn, + ray_remote_args=ray_remote_args, + ) + + @property + def can_modify_num_rows(self) -> bool: + return True diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/n_ary_operator.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/n_ary_operator.py new file mode 100644 index 0000000000000000000000000000000000000000..f2f062578e2c1d1f31b42fe5f96dfbae6cd13654 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/n_ary_operator.py @@ -0,0 +1,60 @@ +from typing import Optional + +from ray.data._internal.logical.interfaces import LogicalOperator + + +class NAry(LogicalOperator): + """Base class for n-ary operators, which take multiple input operators.""" + + def __init__( + self, + *input_ops: LogicalOperator, + num_outputs: Optional[int] = None, + ): + """ + Args: + input_ops: The input operators. + """ + super().__init__(self.__class__.__name__, list(input_ops), num_outputs) + + +class Zip(NAry): + """Logical operator for zip.""" + + def __init__( + self, + left_input_op: LogicalOperator, + right_input_op: LogicalOperator, + ): + """ + Args: + left_input_ops: The input operator at left hand side. + right_input_op: The input operator at right hand side. + """ + super().__init__(left_input_op, right_input_op) + + def estimated_num_outputs(self): + left_num_outputs = self._input_dependencies[0].estimated_num_outputs() + right_num_outputs = self._input_dependencies[1].estimated_num_outputs() + if left_num_outputs is None or right_num_outputs is None: + return None + return max(left_num_outputs, right_num_outputs) + + +class Union(NAry): + """Logical operator for union.""" + + def __init__( + self, + *input_ops: LogicalOperator, + ): + super().__init__(*input_ops) + + def estimated_num_outputs(self): + total_num_outputs = 0 + for input in self._input_dependencies: + num_outputs = input.estimated_num_outputs() + if num_outputs is None: + return None + total_num_outputs += num_outputs + return total_num_outputs diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/one_to_one_operator.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/one_to_one_operator.py new file mode 100644 index 0000000000000000000000000000000000000000..052d0b23ecda047b1876c8ca6adfa9bf6fd8dfa5 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/one_to_one_operator.py @@ -0,0 +1,80 @@ +import abc +from typing import Optional + +from ray.data._internal.logical.interfaces import LogicalOperator +from ray.data.block import BlockMetadata + + +class AbstractOneToOne(LogicalOperator): + """Abstract class for one-to-one logical operators, which + have one input and one output dependency. + """ + + def __init__( + self, + name: str, + input_op: Optional[LogicalOperator], + num_outputs: Optional[int] = None, + ): + """ + Args: + name: Name for this operator. This is the name that will appear when + inspecting the logical plan of a Dataset. + input_op: The operator preceding this operator in the plan DAG. The outputs + of `input_op` will be the inputs to this operator. + """ + super().__init__(name, [input_op] if input_op else [], num_outputs) + + @property + def input_dependency(self) -> LogicalOperator: + return self._input_dependencies[0] + + @property + @abc.abstractmethod + def can_modify_num_rows(self) -> bool: + """Whether this operator can modify the number of rows, + i.e. number of input rows != number of output rows.""" + + +class Limit(AbstractOneToOne): + """Logical operator for limit.""" + + def __init__( + self, + input_op: LogicalOperator, + limit: int, + ): + super().__init__( + f"limit={limit}", + input_op, + ) + self._limit = limit + + @property + def can_modify_num_rows(self) -> bool: + return True + + def aggregate_output_metadata(self) -> BlockMetadata: + return BlockMetadata( + num_rows=self._num_rows(), + size_bytes=None, + schema=self._schema(), + input_files=self._input_files(), + exec_stats=None, + ) + + def _schema(self): + assert len(self._input_dependencies) == 1, len(self._input_dependencies) + return self._input_dependencies[0].aggregate_output_metadata().schema + + def _num_rows(self): + assert len(self._input_dependencies) == 1, len(self._input_dependencies) + input_rows = self._input_dependencies[0].aggregate_output_metadata().num_rows + if input_rows is not None: + return min(input_rows, self._limit) + else: + return None + + def _input_files(self): + assert len(self._input_dependencies) == 1, len(self._input_dependencies) + return self._input_dependencies[0].aggregate_output_metadata().input_files diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/read_operator.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/read_operator.py new file mode 100644 index 0000000000000000000000000000000000000000..5d958dbc59fbd5c0c09312d2c50a59de9f689d41 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/read_operator.py @@ -0,0 +1,95 @@ +import functools +from typing import Any, Dict, Optional, Union + +from ray.data._internal.logical.operators.map_operator import AbstractMap +from ray.data._internal.util import unify_block_metadata_schema +from ray.data.block import BlockMetadata +from ray.data.datasource.datasource import Datasource, Reader + + +class Read(AbstractMap): + """Logical operator for read.""" + + def __init__( + self, + datasource: Datasource, + datasource_or_legacy_reader: Union[Datasource, Reader], + parallelism: int, + mem_size: Optional[int], + num_outputs: Optional[int] = None, + ray_remote_args: Optional[Dict[str, Any]] = None, + concurrency: Optional[int] = None, + ): + super().__init__( + f"Read{datasource.get_name()}", + None, + num_outputs, + ray_remote_args=ray_remote_args, + ) + self._datasource = datasource + self._datasource_or_legacy_reader = datasource_or_legacy_reader + self._parallelism = parallelism + self._mem_size = mem_size + self._concurrency = concurrency + self._detected_parallelism = None + + def set_detected_parallelism(self, parallelism: int): + """ + Set the true parallelism that should be used during execution. This + should be specified by the user or detected by the optimizer. + """ + self._detected_parallelism = parallelism + + def get_detected_parallelism(self) -> int: + """ + Get the true parallelism that should be used during execution. + """ + return self._detected_parallelism + + def aggregate_output_metadata(self) -> BlockMetadata: + """A ``BlockMetadata`` that represents the aggregate metadata of the outputs. + + This method gets metadata from the read tasks. It doesn't trigger any actual + execution. + """ + return self._cached_output_metadata + + @functools.cached_property + def _cached_output_metadata(self) -> BlockMetadata: + # Legacy datasources might not implement `get_read_tasks`. + if self._datasource.should_create_reader: + return BlockMetadata(None, None, None, None, None) + + # HACK: Try to get a single read task to get the metadata. + read_tasks = self._datasource.get_read_tasks(1) + if len(read_tasks) == 0: + # If there are no read tasks, the dataset is probably empty. + return BlockMetadata(None, None, None, None, None) + + # `get_read_tasks` isn't guaranteed to return exactly one read task. + metadata = [read_task.metadata for read_task in read_tasks] + + if all(meta.num_rows is not None for meta in metadata): + num_rows = sum(meta.num_rows for meta in metadata) + else: + num_rows = None + + if all(meta.size_bytes is not None for meta in metadata): + size_bytes = sum(meta.size_bytes for meta in metadata) + else: + size_bytes = None + + schema = unify_block_metadata_schema(metadata) + + input_files = [] + for meta in metadata: + if meta.input_files is not None: + input_files.extend(meta.input_files) + + return BlockMetadata( + num_rows=num_rows, + size_bytes=size_bytes, + schema=schema, + input_files=input_files, + exec_stats=None, + ) diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/write_operator.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/write_operator.py new file mode 100644 index 0000000000000000000000000000000000000000..cee1930b788f9ddc8bcead1150168f635a374658 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/operators/write_operator.py @@ -0,0 +1,35 @@ +from typing import Any, Dict, Optional, Union + +from ray.data._internal.logical.interfaces import LogicalOperator +from ray.data._internal.logical.operators.map_operator import AbstractMap +from ray.data.datasource.datasink import Datasink +from ray.data.datasource.datasource import Datasource + + +class Write(AbstractMap): + """Logical operator for write.""" + + def __init__( + self, + input_op: LogicalOperator, + datasink_or_legacy_datasource: Union[Datasink, Datasource], + ray_remote_args: Optional[Dict[str, Any]] = None, + concurrency: Optional[int] = None, + **write_args, + ): + if isinstance(datasink_or_legacy_datasource, Datasink): + min_rows_per_bundled_input = ( + datasink_or_legacy_datasource.num_rows_per_write + ) + else: + min_rows_per_bundled_input = None + + super().__init__( + "Write", + input_op, + min_rows_per_bundled_input=min_rows_per_bundled_input, + ray_remote_args=ray_remote_args, + ) + self._datasink_or_legacy_datasource = datasink_or_legacy_datasource + self._write_args = write_args + self._concurrency = concurrency diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__init__.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..92a769261403be41df443ab0a740505ecc934ffd --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__init__.py @@ -0,0 +1,4 @@ +from ray.data._internal.logical.rules.operator_fusion import OperatorFusionRule +from ray.data._internal.logical.rules.randomize_blocks import ReorderRandomizeBlocksRule + +__all__ = ["ReorderRandomizeBlocksRule", "OperatorFusionRule"] diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/__init__.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..f26a2066bc1368b859d2b6cc2099cf53749113f8 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/__init__.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/inherit_batch_format.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/inherit_batch_format.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8fc0921f758ab7ceea4b8cd9840c46b32e2eea07 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/inherit_batch_format.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/inherit_target_max_block_size.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/inherit_target_max_block_size.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b6ecca0628b41caa582269e3eab6f1ddb926a7fb Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/inherit_target_max_block_size.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/limit_pushdown.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/limit_pushdown.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..ce0e086d0566c12666ac77f8c0224d7ea0ce7c39 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/limit_pushdown.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/operator_fusion.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/operator_fusion.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2a727c43f824e4c2a1731b0d58ca0c9efa0c119b Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/operator_fusion.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/randomize_blocks.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/randomize_blocks.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b2e893d8f99733de960831dc73280aead225c65e Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/randomize_blocks.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/set_read_parallelism.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/set_read_parallelism.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..628e6811e5a6d55b44fad1fe0da41467ee898bf3 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/set_read_parallelism.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/zero_copy_map_fusion.cpython-310.pyc b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/zero_copy_map_fusion.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..25f123ac637e200e43c3ec24a7ee0953ece58128 Binary files /dev/null and b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/__pycache__/zero_copy_map_fusion.cpython-310.pyc differ diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/inherit_batch_format.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/inherit_batch_format.py new file mode 100644 index 0000000000000000000000000000000000000000..2dd265cd08b119250d08dcf71691e1b3701fb08a --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/inherit_batch_format.py @@ -0,0 +1,42 @@ +from collections import deque +from typing import Iterable + +from ray.data._internal.logical.interfaces import LogicalOperator, LogicalPlan, Rule +from ray.data._internal.logical.operators.all_to_all_operator import AbstractAllToAll +from ray.data._internal.logical.operators.map_operator import MapBatches + + +class InheritBatchFormatRule(Rule): + """For AbstractAllToAll based operator, apply this rule + to inherit batch_format from upstream operator by traversing + the entire DAG.""" + + def apply(self, plan: LogicalPlan) -> LogicalPlan: + optimized_dag: LogicalOperator = self._apply(plan.dag) + new_plan = LogicalPlan(dag=optimized_dag, context=plan.context) + return new_plan + + def _apply(self, op: LogicalOperator): + # Post-order traversal. + nodes: Iterable[LogicalOperator] = deque() + for node in op.post_order_iter(): + nodes.appendleft(node) + + while len(nodes) > 0: + current_op = nodes.pop() + + if isinstance(current_op, AbstractAllToAll): + # traversal up the DAG until we find MapBatches with batch_format + # or we reach to source op and do nothing + upstream_op = current_op.input_dependencies[0] + while upstream_op.input_dependencies: + if ( + isinstance(upstream_op, MapBatches) + and upstream_op._batch_format + ): + current_op._batch_format = upstream_op._batch_format + break + upstream_op = upstream_op.input_dependencies[0] + + # just return the default op + return op diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/inherit_target_max_block_size.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/inherit_target_max_block_size.py new file mode 100644 index 0000000000000000000000000000000000000000..298ff6c4edbff9cfab6ea14418dc61b81c93e1e8 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/inherit_target_max_block_size.py @@ -0,0 +1,30 @@ +from typing import Optional + +from ray.data._internal.execution.interfaces import PhysicalOperator +from ray.data._internal.logical.interfaces import PhysicalPlan, Rule + + +class InheritTargetMaxBlockSizeRule(Rule): + """For each op that has overridden the default target max block size, + propagate to upstream ops until we reach an op that has also overridden the + target max block size.""" + + def apply(self, plan: PhysicalPlan) -> PhysicalPlan: + self._propagate_target_max_block_size_to_upstream_ops(plan.dag) + return plan + + def _propagate_target_max_block_size_to_upstream_ops( + self, dag: PhysicalOperator, target_max_block_size: Optional[int] = None + ): + if dag.target_max_block_size is not None: + # Set the target block size to inherit for + # upstream ops. + target_max_block_size = dag.target_max_block_size + elif target_max_block_size is not None: + # Inherit from downstream op. + dag.set_target_max_block_size(target_max_block_size) + + for upstream_op in dag.input_dependencies: + self._propagate_target_max_block_size_to_upstream_ops( + upstream_op, target_max_block_size + ) diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/limit_pushdown.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/limit_pushdown.py new file mode 100644 index 0000000000000000000000000000000000000000..a13378eb991eb6bdc7e389cf6842ae3df91e66a2 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/limit_pushdown.py @@ -0,0 +1,133 @@ +import copy +from collections import deque +from typing import Iterable, List + +from ray.data._internal.logical.interfaces import LogicalOperator, LogicalPlan, Rule +from ray.data._internal.logical.operators.one_to_one_operator import ( + AbstractOneToOne, + Limit, +) +from ray.data._internal.logical.operators.read_operator import Read + + +class LimitPushdownRule(Rule): + """Rule for pushing down the limit operator. + + When a limit operator is present, we apply the limit on the + most upstream operator that supports it. Notably, we move the + Limit operator downstream from Read op, any other non-OneToOne operator, + or any operator which could potentially change the number of output rows. + + In addition, we also fuse consecutive Limit operators into a single + Limit operator, i.e. `Limit[n] -> Limit[m]` becomes `Limit[min(n, m)]`. + """ + + def apply(self, plan: LogicalPlan) -> LogicalPlan: + optimized_dag = self._apply_limit_pushdown(plan.dag) + optimized_dag = self._apply_limit_fusion(optimized_dag) + return LogicalPlan(dag=optimized_dag, context=plan.context) + + def _apply_limit_pushdown(self, op: LogicalOperator) -> LogicalOperator: + """Given a DAG of LogicalOperators, traverse the DAG and push down + Limit operators, i.e. move Limit operators as far upstream as possible. + + Returns a new LogicalOperator with the Limit operators pushed down.""" + # Post-order traversal. + nodes: Iterable[LogicalOperator] = deque() + for node in op.post_order_iter(): + nodes.appendleft(node) + + while len(nodes) > 0: + current_op = nodes.pop() + + # If we encounter a Limit op, move it upstream until it reaches: + # - Read operator + # - A non-AbstractOneToOne operator (e.g. AbstractAllToAll) + # - An AbstractOneToOne operator that could change the number of output rows + + # TODO(scottjlee): in our current abstraction, we have Read extend + # AbstractMap (with no input dependency), which extends AbstractOneToOne. + # So we have to explicitly separate the Read op in its own check. + # We should remove this case once we refactor Read op to no longer + # be an AbstractOneToOne op. + if isinstance(current_op, Limit): + limit_op_copy = copy.copy(current_op) + + # Traverse up the DAG until we reach the first operator that meets + # one of the conditions above, which will serve as the new input + # into the Limit operator. + new_input_into_limit = current_op.input_dependency + ops_between_new_input_and_limit: List[LogicalOperator] = [] + while ( + isinstance(new_input_into_limit, AbstractOneToOne) + and not isinstance(new_input_into_limit, Read) + and not getattr(new_input_into_limit, "can_modify_num_rows", False) + ): + new_input_into_limit_copy = copy.copy(new_input_into_limit) + ops_between_new_input_and_limit.append(new_input_into_limit_copy) + new_input_into_limit = new_input_into_limit.input_dependency + + # Link the Limit operator and its newly designated input op from above. + limit_op_copy._input_dependencies = [new_input_into_limit] + new_input_into_limit._output_dependencies = [limit_op_copy] + + # Build the chain of operator dependencies between the new + # input and the Limit operator, using copies of traversed operators. + ops_between_new_input_and_limit.append(limit_op_copy) + for idx in range(len(ops_between_new_input_and_limit) - 1): + curr_op, up_op = ( + ops_between_new_input_and_limit[idx], + ops_between_new_input_and_limit[idx + 1], + ) + curr_op._input_dependencies = [up_op] + up_op._output_dependencies = [curr_op] + # Add the copied operator to the list of nodes to be traversed. + nodes.append(curr_op) + + # Link the Limit operator to its new input operator. + for limit_output_op in current_op.output_dependencies: + limit_output_op._input_dependencies = [ + ops_between_new_input_and_limit[0] + ] + last_op = ops_between_new_input_and_limit[0] + last_op._output_dependencies = current_op.output_dependencies + + return current_op + + def _apply_limit_fusion(self, op: LogicalOperator) -> LogicalOperator: + """Given a DAG of LogicalOperators, traverse the DAG and fuse all + back-to-back Limit operators, i.e. + Limit[n] -> Limit[m] becomes Limit[min(n, m)]. + + Returns a new LogicalOperator with the Limit operators fusion applied.""" + + # Post-order traversal. + nodes: Iterable[LogicalOperator] = deque() + for node in op.post_order_iter(): + nodes.appendleft(node) + + while len(nodes) > 0: + current_op = nodes.pop() + + # If we encounter two back-to-back Limit operators, fuse them. + if isinstance(current_op, Limit): + upstream_op = current_op.input_dependency + if isinstance(upstream_op, Limit): + new_limit = min(current_op._limit, upstream_op._limit) + fused_limit_op = Limit(upstream_op.input_dependency, new_limit) + + # Link the fused Limit operator to its input and output ops, i.e.: + # `upstream_input -> limit_upstream -> limit_downstream -> downstream_output` # noqa: E501 + # becomes `upstream_input -> fused_limit -> downstream_output` + fused_limit_op._input_dependencies = upstream_op.input_dependencies + fused_limit_op._output_dependencies = current_op.output_dependencies + + # Replace occurrences of the upstream Limit operator in + # output_dependencies with the newly fused Limit operator. + upstream_input = upstream_op.input_dependency + upstream_input._output_dependencies = [fused_limit_op] + + for current_output in current_op.output_dependencies: + current_output._input_dependencies = [fused_limit_op] + nodes.append(fused_limit_op) + return current_op diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/operator_fusion.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/operator_fusion.py new file mode 100644 index 0000000000000000000000000000000000000000..fef82a3b1f935a2b989c199c9888cc69abe12ec5 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/operator_fusion.py @@ -0,0 +1,464 @@ +from typing import List, Optional, Tuple + +# TODO(Clark): Remove compute dependency once we delete the legacy compute. +from ray.data._internal.compute import get_compute, is_task_compute +from ray.data._internal.execution.interfaces import ( + PhysicalOperator, + RefBundle, + TaskContext, +) +from ray.data._internal.execution.operators.actor_pool_map_operator import ( + ActorPoolMapOperator, +) +from ray.data._internal.execution.operators.base_physical_operator import ( + AllToAllOperator, +) +from ray.data._internal.execution.operators.map_operator import MapOperator +from ray.data._internal.execution.operators.task_pool_map_operator import ( + TaskPoolMapOperator, +) +from ray.data._internal.logical.interfaces import PhysicalPlan, Rule +from ray.data._internal.logical.operators.all_to_all_operator import ( + AbstractAllToAll, + RandomShuffle, + Repartition, +) +from ray.data._internal.logical.operators.map_operator import AbstractUDFMap +from ray.data._internal.stats import StatsDict +from ray.data.context import DataContext + +# Scheduling strategy can be inherited from upstream operator if not specified. +INHERITABLE_REMOTE_ARGS = ["scheduling_strategy"] + + +class OperatorFusionRule(Rule): + """Fuses linear chains of compatible physical operators.""" + + def apply(self, plan: PhysicalPlan) -> PhysicalPlan: + self._op_map = plan.op_map.copy() + # Do DFS fusion on compatible pairwise operators in two passes. + # In the first pass, only fuse back-to-back map operators together. + fused_dag = self._fuse_map_operators_in_dag(plan.dag) + + # Now that we have fused together all back-to-back map operators, + # we fuse together MapOperator -> AllToAllOperator pairs. + fused_dag = self._fuse_all_to_all_operators_in_dag(fused_dag) + + # Update output dependencies after fusion. + # TODO(hchen): Instead of updating the depdencies manually, + # we need a better abstraction for manipulating the DAG. + self._remove_output_depes(fused_dag) + self._update_output_depes(fused_dag) + + new_plan = PhysicalPlan(fused_dag, self._op_map, plan.context) + return new_plan + + def _remove_output_depes(self, op: PhysicalOperator) -> None: + for input in op._input_dependencies: + input._output_dependencies = [] + self._remove_output_depes(input) + + def _update_output_depes(self, op: PhysicalOperator) -> None: + for input in op._input_dependencies: + input._output_dependencies.append(op) + self._update_output_depes(input) + + def _fuse_map_operators_in_dag(self, dag: PhysicalOperator) -> MapOperator: + """Starting at the given operator, traverses up the DAG of operators + and recursively fuses compatible MapOperator -> MapOperator pairs. + Returns the current (root) operator after completing upstream operator fusions. + """ + upstream_ops = dag.input_dependencies + while ( + len(upstream_ops) == 1 + and isinstance(dag, MapOperator) + and isinstance(upstream_ops[0], MapOperator) + and self._can_fuse(dag, upstream_ops[0]) + ): + # Fuse operator with its upstream op. + dag = self._get_fused_map_operator(dag, upstream_ops[0]) + upstream_ops = dag.input_dependencies + + # Done fusing back-to-back map operators together here, + # move up the DAG to find the next map operators to fuse. + dag._input_dependencies = [ + self._fuse_map_operators_in_dag(upstream_op) for upstream_op in upstream_ops + ] + return dag + + def _fuse_all_to_all_operators_in_dag( + self, dag: AllToAllOperator + ) -> AllToAllOperator: + """Starting at the given operator, traverses up the DAG of operators + and recursively fuses compatible MapOperator -> AllToAllOperator pairs. + + Also, sets the target block size of the immediately upstream map op to + match the shuffle block size. We use a larger block size for shuffles + because tiny blocks are bad for I/O performance. + + Returns the current (root) operator after completing upstream operator fusions. + """ + upstream_ops = dag.input_dependencies + while ( + len(upstream_ops) == 1 + and isinstance(dag, AllToAllOperator) + and isinstance(upstream_ops[0], MapOperator) + and self._can_fuse(dag, upstream_ops[0]) + ): + # Fuse operator with its upstream op. + dag = self._get_fused_all_to_all_operator(dag, upstream_ops[0]) + upstream_ops = dag.input_dependencies + + # Done fusing MapOperator -> AllToAllOperator together here, + # move up the DAG to find the next pair of operators to fuse. + dag._input_dependencies = [ + self._fuse_all_to_all_operators_in_dag(upstream_op) + for upstream_op in upstream_ops + ] + return dag + + def _can_fuse(self, down_op: PhysicalOperator, up_op: PhysicalOperator) -> bool: + """Returns whether the provided downstream operator can be fused with the given + upstream operator. + + We currently support fusing two operators if the following are all true: + * We are fusing either MapOperator -> MapOperator or + MapOperator -> AllToAllOperator. + * They either use the same compute configuration, or the upstream operator + uses a task pool while the downstream operator uses an actor pool. + * If both operators involve callable classes, the callable classes are + the same class AND constructor args are the same for both. + * They have compatible remote arguments. + """ + from ray.data._internal.logical.operators.map_operator import ( + AbstractMap, + AbstractUDFMap, + ) + + if not up_op.supports_fusion() or not down_op.supports_fusion(): + return False + + # We currently only support fusing for the following cases: + # - TaskPoolMapOperator -> TaskPoolMapOperator/ActorPoolMapOperator + # - TaskPoolMapOperator -> AllToAllOperator + # (only RandomShuffle and Repartition LogicalOperators are currently supported) + if not ( + ( + isinstance(up_op, TaskPoolMapOperator) + and isinstance(down_op, (TaskPoolMapOperator, ActorPoolMapOperator)) + ) + or ( + isinstance(up_op, TaskPoolMapOperator) + and isinstance(down_op, AllToAllOperator) + ) + ): + return False + + down_logical_op = self._op_map[down_op] + up_logical_op = self._op_map[up_op] + + if up_op.get_additional_split_factor() > 1: + return False + + # If the downstream operator takes no input, it cannot be fused with + # the upstream operator. + if not down_logical_op._input_dependencies: + return False + + # We currently only support fusing for the following cases: + # - AbstractMap -> AbstractMap + # - AbstractMap -> RandomShuffle + # - AbstractMap -> Repartition (shuffle=True) + if not ( + ( + isinstance(up_logical_op, AbstractMap) + and isinstance(down_logical_op, AbstractMap) + ) + or ( + isinstance(up_logical_op, AbstractMap) + and isinstance(down_logical_op, RandomShuffle) + ) + or ( + isinstance(up_logical_op, AbstractMap) + and isinstance(down_logical_op, Repartition) + ) + ): + return False + + # Do not fuse Repartition operator if shuffle is disabled + # (i.e. using split shuffle). + if isinstance(down_logical_op, Repartition) and not down_logical_op._shuffle: + return False + + if isinstance(down_logical_op, AbstractUDFMap) and isinstance( + up_logical_op, AbstractUDFMap + ): + # Allow fusing tasks->actors if the resources are compatible (read->map), + # but not the other way around. The latter (downstream op) will be used as + # the compute if fused. + if is_task_compute(down_logical_op._compute) and get_compute( + up_logical_op._compute + ) != get_compute(down_logical_op._compute): + return False + + # Only fuse if the ops' remote arguments are compatible. + if not _are_remote_args_compatible( + getattr(up_logical_op, "_ray_remote_args", {}), + getattr(down_logical_op, "_ray_remote_args", {}), + ): + return False + + # Do not fuse if either op specifies a `_ray_remote_args_fn`, + # since it is not known whether the generated args will be compatible. + if getattr(up_logical_op, "_ray_remote_args_fn", None) or getattr( + down_logical_op, "_ray_remote_args_fn", None + ): + return False + + if not self._can_merge_target_max_block_size( + up_op.target_max_block_size, down_op.target_max_block_size + ): + return False + + # Otherwise, ops are compatible for fusion. + return True + + def _can_merge_target_max_block_size( + self, + up_target_max_block_size: Optional[int], + down_target_max_block_size: Optional[int], + ): + # If the upstream op overrode the target max block size, only fuse if + # they are equal. + if up_target_max_block_size is not None: + if down_target_max_block_size is None: + down_target_max_block_size = ( + DataContext.get_current().target_max_block_size + ) + if up_target_max_block_size != down_target_max_block_size: + return False + return True + + def _get_merged_target_max_block_size( + self, + up_target_max_block_size: Optional[int], + down_target_max_block_size: Optional[int], + ): + if up_target_max_block_size is not None: + # If the upstream op overrode the target max block size, we can + # only merge if the downstream op matches or uses the default. + assert ( + down_target_max_block_size is None + or down_target_max_block_size == up_target_max_block_size + ) + return up_target_max_block_size + else: + # Upstream op inherits the downstream op's target max block size, + # because the downstream op is the one that outputs the final + # blocks. + return down_target_max_block_size + + def _get_fused_map_operator( + self, down_op: MapOperator, up_op: MapOperator + ) -> MapOperator: + from ray.data._internal.logical.operators.map_operator import AbstractMap + + assert self._can_fuse(down_op, up_op), ( + "Current rule supports fusing MapOperator->MapOperator, but received: " + f"{type(up_op).__name__} -> {type(down_op).__name__}" + ) + + # Fuse operator names. + name = up_op.name + "->" + down_op.name + + down_logical_op = self._op_map.pop(down_op) + up_logical_op = self._op_map.pop(up_op) + + # Merge minimum block sizes. + down_min_rows_per_bundled_input = ( + down_logical_op._min_rows_per_bundled_input + if isinstance(down_logical_op, AbstractMap) + else None + ) + up_min_rows_per_bundled_input = ( + up_logical_op._min_rows_per_bundled_input + if isinstance(up_logical_op, AbstractMap) + else None + ) + if ( + down_min_rows_per_bundled_input is not None + and up_min_rows_per_bundled_input is not None + ): + min_rows_per_bundled_input = max( + down_min_rows_per_bundled_input, up_min_rows_per_bundled_input + ) + elif up_min_rows_per_bundled_input is not None: + min_rows_per_bundled_input = up_min_rows_per_bundled_input + else: + min_rows_per_bundled_input = down_min_rows_per_bundled_input + + target_max_block_size = self._get_merged_target_max_block_size( + up_op.target_max_block_size, down_op.target_max_block_size + ) + + # We take the downstream op's compute in case we're fusing upstream tasks with a + # downstream actor pool (e.g. read->map). + compute = None + if isinstance(down_logical_op, AbstractUDFMap): + compute = get_compute(down_logical_op._compute) + ray_remote_args = up_logical_op._ray_remote_args + ray_remote_args_fn = ( + up_logical_op._ray_remote_args_fn or down_logical_op._ray_remote_args_fn + ) + # Make the upstream operator's inputs the new, fused operator's inputs. + input_deps = up_op.input_dependencies + assert len(input_deps) == 1 + input_op = input_deps[0] + + # Fused physical map operator. + op = MapOperator.create( + up_op.get_map_transformer().fuse(down_op.get_map_transformer()), + input_op, + target_max_block_size=target_max_block_size, + name=name, + compute_strategy=compute, + min_rows_per_bundle=min_rows_per_bundled_input, + ray_remote_args=ray_remote_args, + ray_remote_args_fn=ray_remote_args_fn, + ) + op.set_logical_operators(*up_op._logical_operators, *down_op._logical_operators) + + # Build a map logical operator to be used as a reference for further fusion. + # TODO(Scott): This is hacky, remove this once we push fusion to be purely based + # on a lower-level operator spec. + if isinstance(up_logical_op, AbstractUDFMap): + input_op = up_logical_op.input_dependency + else: + # Bottom out at the source logical op (e.g. Read()). + input_op = up_logical_op + if isinstance(down_logical_op, AbstractUDFMap): + logical_op = AbstractUDFMap( + name, + input_op, + down_logical_op._fn, + down_logical_op._fn_args, + down_logical_op._fn_kwargs, + down_logical_op._fn_constructor_args, + down_logical_op._fn_constructor_kwargs, + min_rows_per_bundled_input, + compute, + ray_remote_args_fn, + ray_remote_args, + ) + else: + from ray.data._internal.logical.operators.map_operator import AbstractMap + + # The downstream op is AbstractMap instead of AbstractUDFMap. + logical_op = AbstractMap( + name, + input_op, + min_rows_per_bundled_input=min_rows_per_bundled_input, + ray_remote_args_fn=ray_remote_args_fn, + ray_remote_args=ray_remote_args, + ) + self._op_map[op] = logical_op + # Return the fused physical operator. + return op + + def _get_fused_all_to_all_operator( + self, down_op: AllToAllOperator, up_op: MapOperator + ) -> AllToAllOperator: + assert self._can_fuse(down_op, up_op), ( + "Current rule supports fusing MapOperator -> AllToAllOperator" + f", but received: {type(up_op).__name__} -> {type(down_op).__name__}" + ) + + # Fuse operator names. + name = up_op.name + "->" + down_op.name + + down_logical_op: AbstractAllToAll = self._op_map.pop(down_op) + up_logical_op: AbstractUDFMap = self._op_map.pop(up_op) + + # Fuse transformation functions. + ray_remote_args = up_logical_op._ray_remote_args + down_transform_fn = down_op.get_transformation_fn() + up_map_transformer = up_op.get_map_transformer() + + def fused_all_to_all_transform_fn( + blocks: List[RefBundle], ctx: TaskContext + ) -> Tuple[List[RefBundle], StatsDict]: + """To fuse MapOperator->AllToAllOperator, we store the map function + in the TaskContext so that it may be used by the downstream + AllToAllOperator's transform function.""" + ctx.upstream_map_transformer = up_map_transformer + ctx.upstream_map_ray_remote_args = ray_remote_args + return down_transform_fn(blocks, ctx) + + # Make the upstream operator's inputs the new, fused operator's inputs. + input_deps = up_op.input_dependencies + assert len(input_deps) == 1 + input_op = input_deps[0] + + target_max_block_size = self._get_merged_target_max_block_size( + up_op.target_max_block_size, down_op.target_max_block_size + ) + + op = AllToAllOperator( + fused_all_to_all_transform_fn, + input_op, + target_max_block_size=target_max_block_size, + num_outputs=down_op._num_outputs, + # Transfer over the existing sub-progress bars from + # the AllToAllOperator (if any) into the fused operator. + sub_progress_bar_names=down_op._sub_progress_bar_names, + name=name, + ) + # Bottom out at the source logical op (e.g. Read()). + input_op = up_logical_op + + if isinstance(down_logical_op, RandomShuffle): + logical_op = RandomShuffle( + input_op, + name=name, + ray_remote_args=ray_remote_args, + ) + elif isinstance(down_logical_op, Repartition): + logical_op = Repartition( + input_op, + num_outputs=down_logical_op._num_outputs, + shuffle=down_logical_op._shuffle, + ) + self._op_map[op] = logical_op + # Return the fused physical operator. + return op + + +def _are_remote_args_compatible(prev_args, next_args): + """Check if Ray remote arguments are compatible for merging.""" + prev_args = _canonicalize(prev_args) + next_args = _canonicalize(next_args) + remote_args = next_args.copy() + for key in INHERITABLE_REMOTE_ARGS: + # NOTE: We only carry over inheritable value in case + # of it not being provided in the remote args + if key in prev_args and key not in remote_args: + remote_args[key] = prev_args[key] + + if prev_args != remote_args: + return False + return True + + +def _canonicalize(remote_args: dict) -> dict: + """Returns canonical form of given remote args.""" + remote_args = remote_args.copy() + if "num_cpus" not in remote_args or remote_args["num_cpus"] is None: + remote_args["num_cpus"] = 1 + if "num_gpus" not in remote_args or remote_args["num_gpus"] is None: + remote_args["num_gpus"] = 0 + resources = remote_args.get("resources", {}) + for k, v in list(resources.items()): + if v is None or v == 0.0: + del resources[k] + remote_args["resources"] = resources + return remote_args diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/randomize_blocks.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/randomize_blocks.py new file mode 100644 index 0000000000000000000000000000000000000000..8810217258ab5b55e3d83eecd41c8e6c2fe4f99f --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/randomize_blocks.py @@ -0,0 +1,77 @@ +import copy +from collections import deque + +from ray.data._internal.logical.interfaces import LogicalOperator, LogicalPlan, Rule +from ray.data._internal.logical.operators.all_to_all_operator import ( + AbstractAllToAll, + RandomizeBlocks, +) + + +class ReorderRandomizeBlocksRule(Rule): + """Rule for reordering RandomizeBlocks logical operator. + + Reordering RandomizeBlocks operators is to help fuse multiple + AbstractUDFMap operators together for better performance. + + 1. Dedupes multiple RandomizeBlocks operators if they are not seeded. + 2. Moves RandomizeBlocks operator to the end of a sequence of AbstractUDFMap + operators. RandomizeBlocks operators are not moved across AbstractAllToAll operator + boundaries. + """ + + def apply(self, plan: LogicalPlan) -> LogicalPlan: + optimized_dag: LogicalOperator = self._apply(plan.dag) + new_plan = LogicalPlan(dag=optimized_dag, context=plan.context) + return new_plan + + def _apply(self, op: LogicalOperator) -> LogicalOperator: + operators = [] + + # Post-order traversal. + nodes = deque() + for node in op.post_order_iter(): + nodes.appendleft(node) + + while len(nodes) > 0: + current_op = nodes.pop() + upstream_ops = current_op.input_dependencies + + # Iterate through all upstream ops, and remove all RandomizeBlocks + # operators. + for i in range(len(upstream_ops)): + if isinstance(upstream_ops[i], RandomizeBlocks): + # If no seeds are provided, then collapse into a single + # RandomizeBlocks operator. + current_seed = upstream_ops[i]._seed + if not operators or current_seed or operators[-1]._seed: + # We need to make a copy of the operator. + # Because the operator instance may be shared by multiple + # Datasets. We shouldn't modify it in place. + operators.append(copy.copy(upstream_ops[i])) + + # Remove RandomizeBlocks operator from the dag and wire in new input + # dependencies. + assert len(upstream_ops[i].input_dependencies) == 1 + upstream_ops[i] = upstream_ops[i].input_dependencies[0] + if isinstance(current_op, AbstractAllToAll) and not isinstance( + current_op, RandomizeBlocks + ): + # If this operator is a an AllToAll Operator, then insert + # RandomizeBlocks right before this operator rather than the end of the + # DAG. + # All-to-all operators can have only 1 input operator. + assert len(upstream_ops) == 1 + input_op = upstream_ops[0] + for random_op in operators: + random_op._input_dependencies = [input_op] + input_op = random_op + upstream_ops[0] = input_op + operators = [] + + # Add RandomizeBlocks operator as the last operator in the DAG if necessary. + for random_op in operators: + random_op._input_dependencies = [op] + op = random_op + + return op diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/set_read_parallelism.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/set_read_parallelism.py new file mode 100644 index 0000000000000000000000000000000000000000..0f9bb1b56ada4375eec9061dc47d30cd1862bd98 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/set_read_parallelism.py @@ -0,0 +1,132 @@ +import logging +import math +from typing import Optional, Tuple, Union + +from ray import available_resources as ray_available_resources +from ray.data._internal.execution.interfaces import PhysicalOperator +from ray.data._internal.execution.operators.input_data_buffer import InputDataBuffer +from ray.data._internal.logical.interfaces import PhysicalPlan, Rule +from ray.data._internal.logical.operators.read_operator import Read +from ray.data._internal.util import _autodetect_parallelism +from ray.data.context import WARN_PREFIX, DataContext +from ray.data.datasource.datasource import Datasource, Reader + +logger = logging.getLogger(__name__) + + +def compute_additional_split_factor( + datasource_or_legacy_reader: Union[Datasource, Reader], + parallelism: int, + mem_size: int, + target_max_block_size: int, + cur_additional_split_factor: Optional[int] = None, +) -> Tuple[int, str, int, Optional[int]]: + ctx = DataContext.get_current() + detected_parallelism, reason, _ = _autodetect_parallelism( + parallelism, target_max_block_size, ctx, datasource_or_legacy_reader, mem_size + ) + num_read_tasks = len( + datasource_or_legacy_reader.get_read_tasks(detected_parallelism) + ) + expected_block_size = None + if mem_size: + expected_block_size = mem_size / num_read_tasks + logger.debug( + f"Expected in-memory size {mem_size}," f" block size {expected_block_size}" + ) + size_based_splits = round(max(1, expected_block_size / target_max_block_size)) + else: + size_based_splits = 1 + if cur_additional_split_factor: + size_based_splits *= cur_additional_split_factor + logger.debug(f"Size based split factor {size_based_splits}") + estimated_num_blocks = num_read_tasks * size_based_splits + logger.debug(f"Blocks after size splits {estimated_num_blocks}") + + available_cpu_slots = ray_available_resources().get("CPU", 1) + if ( + parallelism != -1 + and num_read_tasks >= available_cpu_slots * 4 + and num_read_tasks >= 5000 + ): + logger.warning( + f"{WARN_PREFIX} The requested number of read blocks of {parallelism} " + "is more than 4x the number of available CPU slots in the cluster of " + f"{available_cpu_slots}. This can " + "lead to slowdowns during the data reading phase due to excessive " + "task creation. Reduce the value to match with the available " + "CPU slots in the cluster, or set override_num_blocks to -1 for Ray Data " + "to automatically determine the number of read tasks blocks." + "You can ignore this message if the cluster is expected to autoscale." + ) + + # Add more output splitting for each read task if needed. + # TODO(swang): For parallelism=-1 (user did not explicitly set + # parallelism), and if the following operator produces much larger blocks, + # we should scale down the target max block size here instead of using + # splitting, which can have higher memory usage. + if estimated_num_blocks < detected_parallelism and estimated_num_blocks > 0: + k = math.ceil(detected_parallelism / estimated_num_blocks) + estimated_num_blocks = estimated_num_blocks * k + return detected_parallelism, reason, estimated_num_blocks, k + + return detected_parallelism, reason, estimated_num_blocks, None + + +class SetReadParallelismRule(Rule): + """ + This rule sets the read op's task parallelism based on the target block + size, the requested parallelism, the number of read files, and the + available resources in the cluster. + + If the parallelism is lower than requested, this rule also sets a split + factor to split the output blocks of the read task, so that the following + operator will have the desired parallelism. + """ + + def apply(self, plan: PhysicalPlan) -> PhysicalPlan: + ops = [plan.dag] + + while len(ops) > 0: + op = ops.pop(0) + if isinstance(op, InputDataBuffer): + continue + logical_op = plan.op_map[op] + if isinstance(logical_op, Read): + self._apply(op, logical_op) + ops += op.input_dependencies + + return plan + + def _apply(self, op: PhysicalOperator, logical_op: Read): + ( + detected_parallelism, + reason, + estimated_num_blocks, + k, + ) = compute_additional_split_factor( + logical_op._datasource_or_legacy_reader, + logical_op._parallelism, + logical_op._mem_size, + op.actual_target_max_block_size, + op._additional_split_factor, + ) + + if logical_op._parallelism == -1: + assert reason != "" + logger.debug( + f"Using autodetected parallelism={detected_parallelism} " + f"for operator {logical_op.name} to satisfy {reason}." + ) + logical_op.set_detected_parallelism(detected_parallelism) + + if k is not None: + logger.debug( + f"To satisfy the requested parallelism of {detected_parallelism}, " + f"each read task output is split into {k} smaller blocks." + ) + + if k is not None: + op.set_additional_split_factor(k) + + logger.debug(f"Estimated num output blocks {estimated_num_blocks}") diff --git a/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/zero_copy_map_fusion.py b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/zero_copy_map_fusion.py new file mode 100644 index 0000000000000000000000000000000000000000..6495f64f10a49e781c75b1b5061ba78e66715ad2 --- /dev/null +++ b/vllm/lib/python3.10/site-packages/ray/data/_internal/logical/rules/zero_copy_map_fusion.py @@ -0,0 +1,88 @@ +from abc import abstractmethod +from typing import List + +from ray.data._internal.execution.operators.map_operator import MapOperator +from ray.data._internal.execution.operators.map_transformer import ( + BuildOutputBlocksMapTransformFn, + MapTransformFn, + MapTransformFnDataType, +) +from ray.data._internal.logical.interfaces.optimizer import Rule +from ray.data._internal.logical.interfaces.physical_plan import PhysicalPlan + + +class ZeroCopyMapFusionRule(Rule): + """Base abstract class for all zero-copy map fusion rules. + + A zero-copy map fusion rule is a rule that optimizes the transform_fn chain of + a fused MapOperator. The optimization is usually done by removing unnecessary + data conversions. + + This base abstract class defines the common util functions. And subclasses + should implement the `_optimize` method for the concrete optimization + strategy. + """ + + def apply(self, plan: PhysicalPlan) -> PhysicalPlan: + self._traverse(plan.dag) + return plan + + def _traverse(self, op): + """Traverse the DAG and apply the optimization to each MapOperator.""" + if isinstance(op, MapOperator): + map_transformer = op.get_map_transformer() + transform_fns = map_transformer.get_transform_fns() + new_transform_fns = self._optimize(transform_fns) + # Physical operators won't be shared, + # so it's safe to modify the transform_fns in place. + map_transformer.set_transform_fns(new_transform_fns) + + for input_op in op.input_dependencies: + self._traverse(input_op) + + @abstractmethod + def _optimize(self, transform_fns: List[MapTransformFn]) -> List[MapTransformFn]: + """Optimize the transform_fns chain of a MapOperator. + + Args: + transform_fns: The old transform_fns chain. + Returns: + The optimized transform_fns chain. + """ + ... + + +class EliminateBuildOutputBlocks(ZeroCopyMapFusionRule): + """This rule eliminates unnecessary BuildOutputBlocksMapTransformFn, + if the previous fn already outputs blocks. + + This happens for the "Read -> Map/Write" fusion. + """ + + def _optimize(self, transform_fns: List[MapTransformFn]) -> List[MapTransformFn]: + # For the following subsquence, + # 1. Any MapTransformFn with block output. + # 2. BuildOutputBlocksMapTransformFn + # 3. Any MapTransformFn with block input. + # We drop the BuildOutputBlocksMapTransformFn in the middle. + new_transform_fns = [] + + for i in range(len(transform_fns)): + cur_fn = transform_fns[i] + drop = False + if ( + i > 0 + and i < len(transform_fns) - 1 + and isinstance(cur_fn, BuildOutputBlocksMapTransformFn) + ): + prev_fn = transform_fns[i - 1] + next_fn = transform_fns[i + 1] + if ( + prev_fn.output_type == MapTransformFnDataType.Block + and next_fn.input_type == MapTransformFnDataType.Block + ): + drop = True + if not drop: + new_transform_fns.append(cur_fn) + + return new_transform_fns