Skip to content

Commit 2adc08c

Browse files
committed
Use std::optional
Signed-off-by: cyy <[email protected]>
1 parent 39a5c76 commit 2adc08c

File tree

11 files changed

+114
-114
lines changed

11 files changed

+114
-114
lines changed

backends/cadence/hifi/operators/op_quantized_matmul_out.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void inline _typed_quantized_matmul(
2929
int64_t X_zero_point,
3030
const Tensor& Y,
3131
int64_t Y_zero_point,
32-
const exec_aten::optional<Tensor>& bias,
32+
const std::optional<Tensor>& bias,
3333
int64_t out_multiplier,
3434
int64_t out_shift,
3535
int64_t out_zero_point,
@@ -182,7 +182,7 @@ void quantized_matmul_out(
182182
int64_t X_zero_point,
183183
const Tensor& Y,
184184
int64_t Y_zero_point,
185-
const exec_aten::optional<Tensor>& bias,
185+
const std::optional<Tensor>& bias,
186186
int64_t out_multiplier,
187187
int64_t out_shift,
188188
int64_t out_zero_point,

backends/cadence/hifi/operators/op_slice_copy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Tensor& slice_copy_Tensor_out(
2929
KernelRuntimeContext& ctx,
3030
const Tensor& in,
3131
int64_t dim,
32-
exec_aten::optional<int64_t> start_val,
33-
exec_aten::optional<int64_t> end_val,
32+
std::optional<int64_t> start_val,
33+
std::optional<int64_t> end_val,
3434
int64_t step,
3535
Tensor& out) {
3636
(void)ctx;

backends/cadence/hifi/operators/operators.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void quantized_linear_out(
6767
const ::executorch::aten::Tensor& out_multiplier,
6868
const ::executorch::aten::Tensor& out_shift,
6969
int64_t out_zero_point,
70-
const ::executorch::aten::optional<::executorch::aten::Tensor>& offset,
70+
const ::std::optional<::executorch::aten::Tensor>& offset,
7171
::executorch::aten::Tensor& out);
7272

7373
void quantized_linear_per_tensor_out(
@@ -80,7 +80,7 @@ void quantized_linear_per_tensor_out(
8080
int64_t out_multiplier,
8181
int64_t out_shift,
8282
int64_t out_zero_point,
83-
const ::executorch::aten::optional<::executorch::aten::Tensor>& offset,
83+
const ::std::optional<::executorch::aten::Tensor>& offset,
8484
::executorch::aten::Tensor& out);
8585

8686
void quantized_conv2d_nhwc_out(

backends/vulkan/test/op_tests/dequantize_test.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Tensor& dequantize_per_tensor_out(
3636
int64_t quant_min,
3737
int64_t quant_max,
3838
ScalarType dtype,
39-
executorch::aten::optional<ScalarType> out_dtype,
39+
std::optional<ScalarType> out_dtype,
4040
Tensor& out);
4141

4242
Tensor& dequantize_per_token_out(
@@ -57,7 +57,7 @@ Tensor& dequantize_per_channel_out(
5757
int64_t quant_min,
5858
int64_t quant_max,
5959
ScalarType dtype,
60-
executorch::aten::optional<ScalarType> out_dtype,
60+
std::optional<ScalarType> out_dtype,
6161
Tensor& out);
6262

6363
Tensor& dequantize_per_tensor_tensor_args_out(
@@ -67,7 +67,7 @@ Tensor& dequantize_per_tensor_tensor_args_out(
6767
int64_t quant_min,
6868
int64_t quant_max,
6969
ScalarType dtype,
70-
executorch::aten::optional<ScalarType> out_dtype,
70+
std::optional<ScalarType> out_dtype,
7171
Tensor& out);
7272

7373
// Wrapper function for dequantize_per_tensor_out without context
@@ -78,7 +78,7 @@ Tensor& dequantize_per_tensor_out_no_context(
7878
int64_t quant_min,
7979
int64_t quant_max,
8080
ScalarType dtype,
81-
executorch::aten::optional<ScalarType> out_dtype,
81+
std::optional<ScalarType> out_dtype,
8282
Tensor& out) {
8383
return torch::executor::native::dequantize_per_tensor_out(
8484
input, scale, zero_point, quant_min, quant_max, dtype, out_dtype, out);
@@ -107,7 +107,7 @@ Tensor& dequantize_per_channel_out_no_context(
107107
int64_t quant_min,
108108
int64_t quant_max,
109109
ScalarType dtype,
110-
executorch::aten::optional<ScalarType> out_dtype,
110+
std::optional<ScalarType> out_dtype,
111111
Tensor& out) {
112112
return torch::executor::native::dequantize_per_channel_out(
113113
input,
@@ -129,7 +129,7 @@ Tensor& dequantize_per_tensor_tensor_args_out_no_context(
129129
int64_t quant_min,
130130
int64_t quant_max,
131131
ScalarType dtype,
132-
executorch::aten::optional<ScalarType> out_dtype,
132+
std::optional<ScalarType> out_dtype,
133133
Tensor& out) {
134134
return torch::executor::native::dequantize_per_tensor_tensor_args_out(
135135
input, scale, zero_point, quant_min, quant_max, dtype, out_dtype, out);
@@ -149,7 +149,7 @@ at::Tensor dequantize_per_tensor_aten(
149149
ScalarType et_dtype = at_scalartype_to_et_scalartype(dtype);
150150
ScalarType et_out_dtype = at_scalartype_to_et_scalartype(out_dtype);
151151

152-
executorch::aten::optional<ScalarType> opt_et_out_dtype(et_out_dtype);
152+
std::optional<ScalarType> opt_et_out_dtype(et_out_dtype);
153153

154154
WRAP_TO_ATEN(dequantize_per_tensor_out_no_context, 7)
155155
(input,
@@ -204,7 +204,7 @@ at::Tensor dequantize_per_channel_aten(
204204
ScalarType et_dtype = at_scalartype_to_et_scalartype(dtype);
205205
ScalarType et_out_dtype = at_scalartype_to_et_scalartype(out_dtype);
206206

207-
executorch::aten::optional<ScalarType> opt_et_out_dtype(et_out_dtype);
207+
std::optional<ScalarType> opt_et_out_dtype(et_out_dtype);
208208

209209
WRAP_TO_ATEN(dequantize_per_channel_out_no_context, 8)
210210
(input,
@@ -233,7 +233,7 @@ at::Tensor dequantize_per_tensor_tensor_args_aten(
233233
ScalarType et_dtype = at_scalartype_to_et_scalartype(dtype);
234234
ScalarType et_out_dtype = at_scalartype_to_et_scalartype(out_dtype);
235235

236-
executorch::aten::optional<ScalarType> opt_et_out_dtype(et_out_dtype);
236+
std::optional<ScalarType> opt_et_out_dtype(et_out_dtype);
237237

238238
WRAP_TO_ATEN(dequantize_per_tensor_tensor_args_out_no_context, 7)
239239
(input,

backends/vulkan/test/op_tests/quantize_affine_test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ at::Tensor quantize_affine_reference_impl(
3535
const at::Tensor& input_,
3636
const std::vector<int64_t>& block_size,
3737
const at::Tensor& scale,
38-
const c10::optional<at::Tensor>& zero_point_opt,
38+
const std::optional<at::Tensor>& zero_point_opt,
3939
int64_t quant_min,
4040
int64_t quant_max,
4141
at::ScalarType out_dtype,
42-
c10::optional<std::string> zero_point_domain_opt = std::string("INT")) {
42+
std::optional<std::string> zero_point_domain_opt = std::string("INT")) {
4343
constexpr float kEps = 1e-7f;
4444

4545
const int64_t ndim = input_.dim();
@@ -138,11 +138,11 @@ at::Tensor dequantize_affine_reference_impl(
138138
const at::Tensor& input_,
139139
const std::vector<int64_t>& block_size,
140140
const at::Tensor& scale,
141-
const c10::optional<at::Tensor>& zero_point_opt,
141+
const std::optional<at::Tensor>& zero_point_opt,
142142
int64_t quant_min,
143143
int64_t quant_max,
144144
at::ScalarType out_dtype,
145-
c10::optional<std::string> zero_point_domain_opt = std::string("INT")) {
145+
std::optional<std::string> zero_point_domain_opt = std::string("INT")) {
146146
const int64_t ndim = input_.dim();
147147
_check_dims("input", block_size.size(), ndim);
148148

@@ -252,7 +252,7 @@ at::Tensor quantize_affine_reference_impl(
252252
input,
253253
block_size,
254254
scale,
255-
c10::optional<at::Tensor>(zero_point),
255+
std::optional<at::Tensor>(zero_point),
256256
quant_min,
257257
quant_max,
258258
dtype,
@@ -272,7 +272,7 @@ at::Tensor dequantize_affine_reference_impl(
272272
input,
273273
block_size,
274274
scale,
275-
c10::optional<at::Tensor>(zero_point),
275+
std::optional<at::Tensor>(zero_point),
276276
quant_min,
277277
quant_max,
278278
dtype,
@@ -1373,4 +1373,4 @@ TEST(VulkanChooseQParamsAffineTest, test_symmetric_no_clipping_narrow_range) {
13731373
10, // quant_max (narrow range)
13741374
1e-5, // eps
13751375
at::kFloat); // input dtype
1376-
}
1376+
}

extension/kernel_util/test/make_boxed_from_unboxed_functor_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ add_tensor_out(KernelRuntimeContext& ctx, ArrayRef<Tensor> a, Tensor& out) {
5454

5555
Tensor& add_optional_scalar_out(
5656
KernelRuntimeContext& ctx,
57-
optional<int64_t> s1,
58-
optional<int64_t> s2,
57+
std::optional<int64_t> s1,
58+
std::optional<int64_t> s2,
5959
Tensor& out) {
6060
(void)ctx;
6161
if (s1.has_value()) {
@@ -182,7 +182,7 @@ TEST_F(MakeBoxedFromUnboxedFunctorTest, UnboxOptionalArrayRef) {
182182

183183
// prepare optional tensors.
184184
torch::executor::testing::TensorFactory<ScalarType::Int> tf;
185-
optional<Tensor> storage[2];
185+
std::optional<Tensor> storage[2];
186186
EValue evalues[2] = {EValue(tf.ones({5})), EValue()};
187187
EValue* values_p[2] = {&evalues[0], &evalues[1]};
188188
BoxedEvalueList<optional<Tensor>> a_box(values_p, storage, 2);

extension/llm/custom_ops/op_sdpa.cpp

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ bool validate_flash_attention_args(
3333
const Tensor& query,
3434
const Tensor& key,
3535
const Tensor& value,
36-
const optional<Tensor>& attn_mask) {
36+
const std::optional<Tensor>& attn_mask) {
3737
ET_CHECK_OR_RETURN_FALSE(query.dim() == 4, "query must be a 4D tensor");
3838
ET_CHECK_OR_RETURN_FALSE(key.dim() == 4, "key must be a 4D tensor");
3939
ET_CHECK_OR_RETURN_FALSE(value.dim() == 4, "value must be a 4D tensor");
@@ -245,11 +245,11 @@ Tensor& flash_attention_kernel_out(
245245
const Tensor& query,
246246
const Tensor& key,
247247
const Tensor& value,
248-
const optional<Tensor>& attn_mask,
248+
const std::optional<Tensor>& attn_mask,
249249
const double dropout_p,
250250
const bool is_causal,
251251
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
252-
const optional<double> scale,
252+
const std::optional<double> scale,
253253
Tensor& output) {
254254
(void)ctx;
255255
ET_KERNEL_CHECK(
@@ -281,12 +281,12 @@ Tensor& flash_attention_kernel_out(
281281
is_causal,
282282
attn_mask,
283283
scale,
284-
nullopt,
285-
nullopt,
286-
nullopt,
287-
nullopt,
288-
nullopt,
289-
nullopt);
284+
std::nullopt,
285+
std::nullopt,
286+
std::nullopt,
287+
std::nullopt,
288+
std::nullopt,
289+
std::nullopt);
290290
} else if (seq_len >= 192) {
291291
sdpa::impl::cpu_flash_attention<CTYPE, 64, 512>(
292292
output,
@@ -297,12 +297,12 @@ Tensor& flash_attention_kernel_out(
297297
is_causal,
298298
attn_mask,
299299
scale,
300-
nullopt,
301-
nullopt,
302-
nullopt,
303-
nullopt,
304-
nullopt,
305-
nullopt);
300+
std::nullopt,
301+
std::nullopt,
302+
std::nullopt,
303+
std::nullopt,
304+
std::nullopt,
305+
std::nullopt);
306306
} else {
307307
sdpa::impl::cpu_flash_attention<CTYPE, 32, 512>(
308308
output,
@@ -313,12 +313,12 @@ Tensor& flash_attention_kernel_out(
313313
is_causal,
314314
attn_mask,
315315
scale,
316-
nullopt,
317-
nullopt,
318-
nullopt,
319-
nullopt,
320-
nullopt,
321-
nullopt);
316+
std::nullopt,
317+
std::nullopt,
318+
std::nullopt,
319+
std::nullopt,
320+
std::nullopt,
321+
std::nullopt);
322322
}
323323
});
324324
return output;
@@ -330,18 +330,18 @@ Tensor& custom_sdpa_out_impl(
330330
const Tensor& k,
331331
const Tensor& v,
332332
const int64_t start_pos,
333-
const optional<Tensor>& attn_mask,
333+
const std::optional<Tensor>& attn_mask,
334334
const double dropout_p,
335335
const bool is_causal,
336336
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
337-
const optional<double> scale,
337+
const std::optional<double> scale,
338338
Tensor& output,
339-
const optional<Tensor>& q_zero_points = nullopt,
340-
const optional<Tensor>& q_scales = nullopt,
341-
const optional<Tensor>& k_zero_points = nullopt,
342-
const optional<Tensor>& k_scales = nullopt,
343-
const optional<Tensor>& v_zero_points = nullopt,
344-
const optional<Tensor>& v_scales = nullopt,
339+
const std::optional<Tensor>& q_zero_points = std::nullopt,
340+
const std::optional<Tensor>& q_scales = std::nullopt,
341+
const std::optional<Tensor>& k_zero_points = std::nullopt,
342+
const std::optional<Tensor>& k_scales = std::nullopt,
343+
const std::optional<Tensor>& v_zero_points = std::nullopt,
344+
const std::optional<Tensor>& v_scales = std::nullopt,
345345
bool is_seq_at_dim_2 = false) {
346346
ET_KERNEL_CHECK_MSG(
347347
ctx,
@@ -484,17 +484,17 @@ Tensor& custom_quantized_sdpa_out(
484484
const Tensor& k,
485485
const Tensor& v,
486486
const int64_t start_pos,
487-
const optional<Tensor>& attn_mask,
487+
const std::optional<Tensor>& attn_mask,
488488
const double dropout_p,
489489
const bool is_causal,
490490
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
491-
const optional<double> scale,
492-
const optional<Tensor>& q_zero_points,
493-
const optional<Tensor>& q_scales,
494-
const optional<Tensor>& k_zero_points,
495-
const optional<Tensor>& k_scales,
496-
const optional<Tensor>& v_zero_points,
497-
const optional<Tensor>& v_scales,
491+
const std::optional<double> scale,
492+
const std::optional<Tensor>& q_zero_points,
493+
const std::optional<Tensor>& q_scales,
494+
const std::optional<Tensor>& k_zero_points,
495+
const std::optional<Tensor>& k_scales,
496+
const std::optional<Tensor>& v_zero_points,
497+
const std::optional<Tensor>& v_scales,
498498
const bool is_seq_at_dim_2,
499499
Tensor& output) {
500500
return custom_sdpa_out_impl(
@@ -538,11 +538,11 @@ Tensor& custom_sdpa_out(
538538
const Tensor& k,
539539
const Tensor& v,
540540
const int64_t start_pos,
541-
const optional<Tensor>& attn_mask,
541+
const std::optional<Tensor>& attn_mask,
542542
const double dropout_p,
543543
const bool is_causal,
544544
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
545-
const optional<double> scale,
545+
const std::optional<double> scale,
546546
Tensor& output) {
547547
return custom_sdpa_out_impl(
548548
ctx, q, k, v, start_pos, attn_mask, dropout_p, is_causal, scale, output);
@@ -572,11 +572,11 @@ Tensor& sdpa_with_kv_cache_out(
572572
Tensor& value_cache,
573573
const int64_t start_pos,
574574
const int64_t seq_len,
575-
const optional<Tensor>& attn_mask,
575+
const std::optional<Tensor>& attn_mask,
576576
const double dropout_p,
577577
const bool is_causal,
578578
// @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
579-
const optional<double> scale,
579+
const std::optional<double> scale,
580580
Tensor& output) {
581581
(void)ctx;
582582
ET_KERNEL_CHECK(

0 commit comments

Comments
 (0)