diff --git a/csrc/common/pytorch_shim.h b/csrc/common/pytorch_shim.h index ef1f0635a87..f27e150c827 100644 --- a/csrc/common/pytorch_shim.h +++ b/csrc/common/pytorch_shim.h @@ -15,13 +15,13 @@ * that the following types are not support by PyTorch libary bindings: * - `int` * - `float` - * - `c10::optional &` - * - `c10::optional &` + * - `std::optional &` + * - `std::optional &` * So we convert them to (respectively): * - `int64_t` * - `double` - * - `const c10::optional&` - * - `const c10::optional&` + * - `const std::optional&` + * - `const std::optional&` */ template @@ -38,36 +38,36 @@ template T convert_from_pytorch_compatible_type(pytorch_library_compatible_type_t arg) { return pytorch_library_compatible_type::convert_from_type(arg); } -// Map `c10::optional &` -> `const c10::optional&` +// Map `std::optional &` -> `const std::optional&` // (NOTE: this is bit unsafe but non of the ops in flash_attn mutate // the optional container) template -struct pytorch_library_compatible_type &> { - using type = const c10::optional&; - static c10::optional& convert_from_type(const c10::optional &arg) { - return const_cast&>(arg); +struct pytorch_library_compatible_type &> { + using type = const std::optional&; + static std::optional& convert_from_type(const std::optional &arg) { + return const_cast&>(arg); } }; -// Map `c10::optional` -> -// `c10::optional>` -// (NOTE: tested for `c10::optional` -> `c10::optional`) +// Map `std::optional` -> +// `std::optional>` +// (NOTE: tested for `std::optional` -> `std::optional`) template -struct pytorch_library_compatible_type> { - using type = c10::optional>; - static c10::optional> convert_from_type(c10::optional arg) { +struct pytorch_library_compatible_type> { + using type = std::optional>; + static std::optional> convert_from_type(std::optional arg) { return arg; } }; -// Map `c10::optional&` -> `const c10::optional&` +// Map `std::optional&` -> `const std::optional&` template<> -struct pytorch_library_compatible_type &> { - using type = const c10::optional&; - static c10::optional& convert_from_type( - const c10::optional &arg) { - return const_cast&>( - reinterpret_cast&>(arg)); +struct pytorch_library_compatible_type &> { + using type = const std::optional&; + static std::optional& convert_from_type( + const std::optional &arg) { + return const_cast&>( + reinterpret_cast&>(arg)); } }; diff --git a/csrc/flash_attn/flash_api_sparse.cpp b/csrc/flash_attn/flash_api_sparse.cpp index e59e0ad94a0..36d87fa9c57 100644 --- a/csrc/flash_attn/flash_api_sparse.cpp +++ b/csrc/flash_attn/flash_api_sparse.cpp @@ -318,11 +318,11 @@ mha_varlen_fwd_sparse(at::Tensor &q, // total_q x num_heads x head_size, total_ const at::Tensor &block_offset, const at::Tensor &column_count, const at::Tensor &column_index, - const c10::optional &out_, // total_q x num_heads x head_size, total_k := \sum_{i=0}^{b} s_i + const std::optional &out_, // total_q x num_heads x head_size, total_k := \sum_{i=0}^{b} s_i const at::Tensor &cu_seqlens_q, // b+1 const at::Tensor &cu_seqlens_k, // b+1 - const c10::optional &seqused_k, // b. If given, only this many elements of each batch element's keys are used. - const c10::optional &alibi_slopes_, // num_heads or b x num_heads + const std::optional &seqused_k, // b. If given, only this many elements of each batch element's keys are used. + const std::optional &alibi_slopes_, // num_heads or b x num_heads int64_t max_seqlen_q, const int64_t max_seqlen_k, const double p_dropout, @@ -331,7 +331,7 @@ mha_varlen_fwd_sparse(at::Tensor &q, // total_q x num_heads x head_size, total_ bool is_causal, const double softcap, const bool return_softmax, - c10::optional gen_) { + std::optional gen_) { auto [cc_major, cc_minor] = get_compute_capability(get_current_device()); bool is_sm8x = cc_major == 8 && cc_minor >= 0; diff --git a/csrc/flash_attn/flash_api_torch_lib.cpp b/csrc/flash_attn/flash_api_torch_lib.cpp index 5c3f7af5d64..d1299c54cd9 100644 --- a/csrc/flash_attn/flash_api_torch_lib.cpp +++ b/csrc/flash_attn/flash_api_torch_lib.cpp @@ -86,11 +86,11 @@ mha_varlen_fwd_sparse(at::Tensor &q, // total_q x num_heads x head_size, total_ const at::Tensor &block_offset, const at::Tensor &column_count, const at::Tensor &column_index, - const c10::optional &out_, // total_q x num_heads x head_size, total_k := \sum_{i=0}^{b} s_i + const std::optional &out_, // total_q x num_heads x head_size, total_k := \sum_{i=0}^{b} s_i const at::Tensor &cu_seqlens_q, // b+1 const at::Tensor &cu_seqlens_k, // b+1 - const c10::optional &seqused_k, // b. If given, only this many elements of each batch element's keys are used. - const c10::optional &alibi_slopes_, // num_heads or b x num_heads + const std::optional &seqused_k, // b. If given, only this many elements of each batch element's keys are used. + const std::optional &alibi_slopes_, // num_heads or b x num_heads int64_t max_seqlen_q, const int64_t max_seqlen_k, const double p_dropout, @@ -99,7 +99,7 @@ mha_varlen_fwd_sparse(at::Tensor &q, // total_q x num_heads x head_size, total_ bool is_causal, const double softcap, const bool return_softmax, - c10::optional gen_); + std::optional gen_); /** * Torch Library Registration