Skip to content

Commit a19d1ba

Browse files
authored
Revert "Remove c10 shim includes and redundant std type aliases" (#21050)
Reverts #20900 This causes many internal build failures in internal code like: ``` error: 'using executorch::aten::string_view = class std::basic_string_view<char>' is deprecated [-Werror=deprecated-declarations] 82 | ET_UNUSED std::string_view key) const override { ```
1 parent 564e655 commit a19d1ba

31 files changed

Lines changed: 150 additions & 144 deletions

backends/cadence/fusion_g3/operators/op_dequantize.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <algorithm>
1212
#include <cinttypes>
1313
#include <cmath>
14-
#include <optional>
1514

1615
#include <xa_nnlib_kernels_api.h>
1716

@@ -23,6 +22,8 @@ using ::executorch::aten::ScalarType;
2322
using ::executorch::aten::Tensor;
2423
using ::executorch::runtime::KernelRuntimeContext;
2524

25+
template <typename T>
26+
using optional = std::optional<T>;
2627
/* ScalarType in Executorch do not have support for below data types.
2728
* So, creating a placeholder for these data types. Once, ScalarTypes is
2829
* updated to have support for below data types, these can be removed and
@@ -294,7 +295,7 @@ Tensor& dequantize_impl(
294295
const auto* input_data_ptr = input.const_data_ptr<CTYPE_IN>(); \
295296
ET_CHECK_MSG( \
296297
*axis == 0, "Axis must be 0 for a single dimensional tensors"); \
297-
const std::optional<int64_t> dim; \
298+
const optional<int64_t> dim; \
298299
torch::executor::apply_over_dim( \
299300
[input_data_ptr, out_data_ptr, zero_point_data, scale_data]( \
300301
size_t numel, size_t stride, size_t base_ix) { \
@@ -500,7 +501,7 @@ Tensor& dequantize_impl(
500501
const auto* input_data_ptr = input.const_data_ptr<CTYPE_IN>(); \
501502
ET_CHECK_MSG( \
502503
*axis == 0, "Axis must be 0 for a single dimensional tensors"); \
503-
const std::optional<int64_t> dim; \
504+
const optional<int64_t> dim; \
504505
torch::executor::apply_over_dim( \
505506
[input_data_ptr, out_data_ptr, zero_point_data, scale_data]( \
506507
size_t numel, size_t stride, size_t base_ix) { \

extension/llm/custom_ops/op_sdpa.cpp

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ bool validate_flash_attention_args(
3838
const Tensor& query,
3939
const Tensor& key,
4040
const Tensor& value,
41-
const std::optional<Tensor>& attn_mask) {
41+
const optional<Tensor>& attn_mask) {
4242
ET_CHECK_OR_RETURN_FALSE(query.dim() == 4, "query must be a 4D tensor");
4343
ET_CHECK_OR_RETURN_FALSE(key.dim() == 4, "key must be a 4D tensor");
4444
ET_CHECK_OR_RETURN_FALSE(value.dim() == 4, "value must be a 4D tensor");
@@ -325,11 +325,11 @@ Tensor& flash_attention_kernel_out(
325325
const Tensor& query,
326326
const Tensor& key,
327327
const Tensor& value,
328-
const std::optional<Tensor>& attn_mask,
328+
const optional<Tensor>& attn_mask,
329329
const double dropout_p,
330330
const bool is_causal,
331331
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
332-
const std::optional<double> scale,
332+
const optional<double> scale,
333333
Tensor& output) {
334334
(void)ctx;
335335
ET_KERNEL_CHECK(
@@ -362,12 +362,12 @@ Tensor& flash_attention_kernel_out(
362362
is_causal,
363363
attn_mask,
364364
scale,
365-
std::nullopt,
366-
std::nullopt,
367-
std::nullopt,
368-
std::nullopt,
369-
std::nullopt,
370-
std::nullopt);
365+
nullopt,
366+
nullopt,
367+
nullopt,
368+
nullopt,
369+
nullopt,
370+
nullopt);
371371
} else if (seq_len >= 192) {
372372
sdpa::impl::cpu_flash_attention<CTYPE, 64, 512>(
373373
ctx,
@@ -379,12 +379,12 @@ Tensor& flash_attention_kernel_out(
379379
is_causal,
380380
attn_mask,
381381
scale,
382-
std::nullopt,
383-
std::nullopt,
384-
std::nullopt,
385-
std::nullopt,
386-
std::nullopt,
387-
std::nullopt);
382+
nullopt,
383+
nullopt,
384+
nullopt,
385+
nullopt,
386+
nullopt,
387+
nullopt);
388388
} else {
389389
sdpa::impl::cpu_flash_attention<CTYPE, 32, 512>(
390390
ctx,
@@ -396,12 +396,12 @@ Tensor& flash_attention_kernel_out(
396396
is_causal,
397397
attn_mask,
398398
scale,
399-
std::nullopt,
400-
std::nullopt,
401-
std::nullopt,
402-
std::nullopt,
403-
std::nullopt,
404-
std::nullopt);
399+
nullopt,
400+
nullopt,
401+
nullopt,
402+
nullopt,
403+
nullopt,
404+
nullopt);
405405
}
406406
});
407407
return output;
@@ -413,18 +413,18 @@ Tensor& custom_sdpa_out_impl(
413413
const Tensor& k,
414414
const Tensor& v,
415415
const int64_t start_pos,
416-
const std::optional<Tensor>& attn_mask,
416+
const optional<Tensor>& attn_mask,
417417
const double dropout_p,
418418
const bool is_causal,
419419
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
420-
const std::optional<double> scale,
420+
const optional<double> scale,
421421
Tensor& output,
422-
const std::optional<Tensor>& q_zero_points = std::nullopt,
423-
const std::optional<Tensor>& q_scales = std::nullopt,
424-
const std::optional<Tensor>& k_zero_points = std::nullopt,
425-
const std::optional<Tensor>& k_scales = std::nullopt,
426-
const std::optional<Tensor>& v_zero_points = std::nullopt,
427-
const std::optional<Tensor>& v_scales = std::nullopt,
422+
const optional<Tensor>& q_zero_points = nullopt,
423+
const optional<Tensor>& q_scales = nullopt,
424+
const optional<Tensor>& k_zero_points = nullopt,
425+
const optional<Tensor>& k_scales = nullopt,
426+
const optional<Tensor>& v_zero_points = nullopt,
427+
const optional<Tensor>& v_scales = nullopt,
428428
bool is_seq_at_dim_2 = false) {
429429
ET_KERNEL_CHECK_MSG(
430430
ctx,
@@ -570,17 +570,17 @@ Tensor& custom_quantized_sdpa_out(
570570
const Tensor& k,
571571
const Tensor& v,
572572
const int64_t start_pos,
573-
const std::optional<Tensor>& attn_mask,
573+
const optional<Tensor>& attn_mask,
574574
const double dropout_p,
575575
const bool is_causal,
576576
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
577-
const std::optional<double> scale,
578-
const std::optional<Tensor>& q_zero_points,
579-
const std::optional<Tensor>& q_scales,
580-
const std::optional<Tensor>& k_zero_points,
581-
const std::optional<Tensor>& k_scales,
582-
const std::optional<Tensor>& v_zero_points,
583-
const std::optional<Tensor>& v_scales,
577+
const optional<double> scale,
578+
const optional<Tensor>& q_zero_points,
579+
const optional<Tensor>& q_scales,
580+
const optional<Tensor>& k_zero_points,
581+
const optional<Tensor>& k_scales,
582+
const optional<Tensor>& v_zero_points,
583+
const optional<Tensor>& v_scales,
584584
const bool is_seq_at_dim_2,
585585
Tensor& output) {
586586
return custom_sdpa_out_impl(
@@ -624,11 +624,11 @@ Tensor& custom_sdpa_out(
624624
const Tensor& k,
625625
const Tensor& v,
626626
const int64_t start_pos,
627-
const std::optional<Tensor>& attn_mask,
627+
const optional<Tensor>& attn_mask,
628628
const double dropout_p,
629629
const bool is_causal,
630630
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
631-
const std::optional<double> scale,
631+
const optional<double> scale,
632632
Tensor& output) {
633633
return custom_sdpa_out_impl(
634634
ctx, q, k, v, start_pos, attn_mask, dropout_p, is_causal, scale, output);
@@ -658,11 +658,11 @@ Tensor& sdpa_with_kv_cache_out(
658658
Tensor& value_cache,
659659
const int64_t start_pos,
660660
const int64_t seq_len,
661-
const std::optional<Tensor>& attn_mask,
661+
const optional<Tensor>& attn_mask,
662662
const double dropout_p,
663663
const bool is_causal,
664664
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
665-
const std::optional<double> scale,
665+
const optional<double> scale,
666666
Tensor& output) {
667667
(void)ctx;
668668
ET_KERNEL_CHECK(

extension/llm/custom_ops/op_sdpa.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ Tensor& sdpa_with_kv_cache_out(
2626
Tensor& value_cache,
2727
const int64_t start_pos,
2828
const int64_t seq_len,
29-
const std::optional<Tensor>& attn_mask,
29+
const optional<Tensor>& attn_mask,
3030
const double dropout_p,
3131
const bool is_causal,
3232
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
33-
const std::optional<double> scale,
33+
const optional<double> scale,
3434
Tensor& output);
3535

3636
Tensor& custom_sdpa_out(
@@ -39,23 +39,23 @@ Tensor& custom_sdpa_out(
3939
const Tensor& k,
4040
const Tensor& v,
4141
const int64_t start_pos,
42-
const std::optional<Tensor>& attn_mask,
42+
const optional<Tensor>& attn_mask,
4343
const double dropout_p,
4444
const bool is_causal,
4545
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
46-
const std::optional<double> scale,
46+
const optional<double> scale,
4747
Tensor& output);
4848

4949
Tensor& flash_attention_kernel_out(
5050
KernelRuntimeContext& ctx,
5151
const Tensor& query,
5252
const Tensor& key,
5353
const Tensor& value,
54-
const std::optional<Tensor>& attn_mask,
54+
const optional<Tensor>& attn_mask,
5555
const double dropout_p,
5656
const bool is_causal,
5757
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
58-
const std::optional<double> scale,
58+
const optional<double> scale,
5959
Tensor& output);
6060

6161
Tensor& custom_quantized_sdpa_out(
@@ -64,17 +64,17 @@ Tensor& custom_quantized_sdpa_out(
6464
const Tensor& k,
6565
const Tensor& v,
6666
const int64_t start_pos,
67-
const std::optional<Tensor>& attn_mask,
67+
const optional<Tensor>& attn_mask,
6868
const double dropout_p,
6969
const bool is_causal,
7070
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
71-
const std::optional<double> scale,
72-
const std::optional<Tensor>& q_zero_points,
73-
const std::optional<Tensor>& q_scales,
74-
const std::optional<Tensor>& k_zero_points,
75-
const std::optional<Tensor>& k_scales,
76-
const std::optional<Tensor>& v_zero_points,
77-
const std::optional<Tensor>& v_scales,
71+
const optional<double> scale,
72+
const optional<Tensor>& q_zero_points,
73+
const optional<Tensor>& q_scales,
74+
const optional<Tensor>& k_zero_points,
75+
const optional<Tensor>& k_scales,
76+
const optional<Tensor>& v_zero_points,
77+
const optional<Tensor>& v_scales,
7878
const bool is_seq_at_dim_1,
7979
Tensor& output);
8080

extension/llm/custom_ops/op_sdpa_aot.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ Tensor& sdpa_with_kv_cache_out_no_context(
2727
const int64_t seq_len,
2828
// @lint-ignore CLANGTIDY facebook-hte-ConstantArgumentPassByValue
2929
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
30-
const std::optional<Tensor> attn_mask,
30+
const optional<Tensor> attn_mask,
3131
const double dropout_p,
3232
const bool is_causal,
3333
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
34-
const std::optional<double> scale,
34+
const optional<double> scale,
3535
Tensor& output);
3636

3737
at::Tensor sdpa_with_kv_cache_aten(
@@ -57,11 +57,11 @@ Tensor& custom_sdpa_out_no_context(
5757
const int64_t start_pos,
5858
// @lint-ignore CLANGTIDY facebook-hte-ConstantArgumentPassByValue
5959
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
60-
const std::optional<Tensor> attn_mask,
60+
const optional<Tensor> attn_mask,
6161
const double dropout_p,
6262
const bool is_causal,
6363
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
64-
const std::optional<double> scale,
64+
const optional<double> scale,
6565
Tensor& output);
6666

6767
at::Tensor custom_sdpa_aten(
@@ -84,17 +84,17 @@ Tensor& custom_quantized_sdpa_out_no_context(
8484
const int64_t start_pos,
8585
// @lint-ignore CLANGTIDY facebook-hte-ConstantArgumentPassByValue
8686
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
87-
const std::optional<Tensor> attn_mask,
87+
const optional<Tensor> attn_mask,
8888
const double dropout_p,
8989
const bool is_causal,
9090
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
91-
const std::optional<double> scale,
92-
const std::optional<Tensor> q_zero_points,
93-
const std::optional<Tensor> q_scales,
94-
const std::optional<Tensor> k_zero_points,
95-
const std::optional<Tensor> k_scales,
96-
const std::optional<Tensor> v_zero_points,
97-
const std::optional<Tensor> v_scales,
91+
const optional<double> scale,
92+
const optional<Tensor> q_zero_points,
93+
const optional<Tensor> q_scales,
94+
const optional<Tensor> k_zero_points,
95+
const optional<Tensor> k_scales,
96+
const optional<Tensor> v_zero_points,
97+
const optional<Tensor> v_scales,
9898
const bool is_seq_at_dim_2,
9999
Tensor& output);
100100

@@ -153,11 +153,11 @@ Tensor& sdpa_with_kv_cache_out_no_context(
153153
const int64_t seq_len,
154154
// @lint-ignore CLANGTIDY facebook-hte-ConstantArgumentPassByValue
155155
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
156-
const std::optional<Tensor> attn_mask,
156+
const optional<Tensor> attn_mask,
157157
const double dropout_p,
158158
const bool is_causal,
159159
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
160-
const std::optional<double> scale,
160+
const optional<double> scale,
161161
Tensor& output) {
162162
executorch::runtime::KernelRuntimeContext context{};
163163
return torch::executor::native::sdpa_with_kv_cache_out(
@@ -215,11 +215,11 @@ Tensor& custom_sdpa_out_no_context(
215215
const int64_t start_pos,
216216
// @lint-ignore CLANGTIDY facebook-hte-ConstantArgumentPassByValue
217217
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
218-
const std::optional<Tensor> attn_mask,
218+
const optional<Tensor> attn_mask,
219219
const double dropout_p,
220220
const bool is_causal,
221221
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
222-
const std::optional<double> scale,
222+
const optional<double> scale,
223223
Tensor& output) {
224224
executorch::aten::RuntimeContext context{};
225225
return torch::executor::native::custom_sdpa_out(
@@ -260,17 +260,17 @@ Tensor& custom_quantized_sdpa_out_no_context(
260260
const int64_t start_pos,
261261
// @lint-ignore CLANGTIDY facebook-hte-ConstantArgumentPassByValue
262262
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
263-
const std::optional<Tensor> attn_mask,
263+
const optional<Tensor> attn_mask,
264264
const double dropout_p,
265265
const bool is_causal,
266266
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
267-
const std::optional<double> scale,
268-
const std::optional<Tensor> q_zero_points,
269-
const std::optional<Tensor> q_scales,
270-
const std::optional<Tensor> k_zero_points,
271-
const std::optional<Tensor> k_scales,
272-
const std::optional<Tensor> v_zero_points,
273-
const std::optional<Tensor> v_scales,
267+
const optional<double> scale,
268+
const optional<Tensor> q_zero_points,
269+
const optional<Tensor> q_scales,
270+
const optional<Tensor> k_zero_points,
271+
const optional<Tensor> k_scales,
272+
const optional<Tensor> v_zero_points,
273+
const optional<Tensor> v_scales,
274274
const bool is_seq_at_dim_2,
275275
Tensor& output) {
276276
executorch::aten::RuntimeContext context{};

extension/llm/custom_ops/op_sdpa_impl.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -613,14 +613,14 @@ void cpu_flash_attention(
613613
const Tensor& value,
614614
double dropout_p,
615615
bool is_causal,
616-
const std::optional<Tensor>& attn_mask,
617-
const std::optional<double>& scale,
618-
const std::optional<Tensor>& q_zero_points,
619-
const std::optional<Tensor>& q_scales,
620-
const std::optional<Tensor>& k_zero_points,
621-
const std::optional<Tensor>& k_scales,
622-
const std::optional<Tensor>& v_zero_points,
623-
const std::optional<Tensor>& v_scales,
616+
const optional<Tensor>& attn_mask,
617+
const optional<double>& scale,
618+
const optional<Tensor>& q_zero_points,
619+
const optional<Tensor>& q_scales,
620+
const optional<Tensor>& k_zero_points,
621+
const optional<Tensor>& k_scales,
622+
const optional<Tensor>& v_zero_points,
623+
const optional<Tensor>& v_scales,
624624
const SeqDim seq_dim = SeqDim::TWO,
625625
const int64_t start_pos = 0,
626626
const int64_t num_keys_for_causal_attention = -1) {

0 commit comments

Comments
 (0)