From c31a749143fda4c18d9450c46b94dddfbaa99a86 Mon Sep 17 00:00:00 2001 From: claude Date: Tue, 11 Aug 2026 07:40:42 +0000 Subject: [PATCH] fix(build): std::optional -> c10::optional in ALL ilu/ files including ixformer.h --- ex_engine/csrc/ilu/attention.cpp | 38 +++++++++---------- ex_engine/csrc/ilu/fused_moe.cpp | 14 +++---- ex_engine/csrc/ilu/group_gemm.cpp | 4 +- ex_engine/csrc/ilu/ixformer.h | 20 +++++----- ex_engine/csrc/ilu/layer_attention.cpp | 36 +++++++++--------- ex_engine/csrc/ilu/layer_attention.h | 6 +-- ex_engine/csrc/ilu/layer_fused_moe.cpp | 16 ++++---- ex_engine/csrc/ilu/layer_fused_moe.h | 4 +- ex_engine/csrc/ilu/matmul.cpp | 2 +- ex_engine/csrc/ilu/norm.cpp | 8 ++-- .../csrc/ilu/qwen3_gated_delta_net_base.cpp | 6 +-- 11 files changed, 77 insertions(+), 77 deletions(-) diff --git a/ex_engine/csrc/ilu/attention.cpp b/ex_engine/csrc/ilu/attention.cpp index 3d572f5a..bd7fb89a 100644 --- a/ex_engine/csrc/ilu/attention.cpp +++ b/ex_engine/csrc/ilu/attention.cpp @@ -23,9 +23,9 @@ using namespace ixformer; namespace xllm::kernel::ilu { void reshape_paged_cache(torch::Tensor& key, - std::optional& value, + c10::optional& value, torch::Tensor& key_cache, - std::optional& value_cache, + c10::optional& value_cache, torch::Tensor& slot_mapping) { auto value_ = value.value_or(torch::Tensor()); auto value_cache_ = value_cache.value_or(torch::Tensor()); @@ -47,16 +47,16 @@ void reshape_paged_cache(torch::Tensor& key, void batch_prefill(torch::Tensor& query, const torch::Tensor& key, - const std::optional& value, + const c10::optional& value, torch::Tensor& output, - std::optional& output_lse, - const std::optional& q_cu_seq_lens, - const std::optional& kv_cu_seq_lens, - const std::optional& alibi_slope, - const std::optional& attn_bias, - const std::optional& q_quant_scale, - const std::optional& k_quant_scale, - const std::optional& v_quant_scale, + c10::optional& output_lse, + const c10::optional& q_cu_seq_lens, + const c10::optional& kv_cu_seq_lens, + const c10::optional& alibi_slope, + const c10::optional& attn_bias, + const c10::optional& q_quant_scale, + const c10::optional& k_quant_scale, + const c10::optional& v_quant_scale, const torch::Tensor& block_tables, int64_t max_query_len, int64_t max_seq_len, @@ -101,14 +101,14 @@ void batch_decode(torch::Tensor& query, torch::Tensor& output, const torch::Tensor& block_table, const torch::Tensor& seq_lens, - const std::optional& v_cache, - std::optional& output_lse, - const std::optional& q_quant_scale, - const std::optional& k_cache_quant_scale, - const std::optional& v_cache_quant_scale, - const std::optional& out_quant_scale, - const std::optional& alibi_slope, - const std::optional& mask, + const c10::optional& v_cache, + c10::optional& output_lse, + const c10::optional& q_quant_scale, + const c10::optional& k_cache_quant_scale, + const c10::optional& v_cache_quant_scale, + const c10::optional& out_quant_scale, + const c10::optional& alibi_slope, + const c10::optional& mask, const std::string& compute_dtype, int64_t max_seq_len, int64_t window_size_left, diff --git a/ex_engine/csrc/ilu/fused_moe.cpp b/ex_engine/csrc/ilu/fused_moe.cpp index 30ccbada..df0df810 100644 --- a/ex_engine/csrc/ilu/fused_moe.cpp +++ b/ex_engine/csrc/ilu/fused_moe.cpp @@ -25,11 +25,11 @@ std::tuple moe_active_topk( int64_t num_expert_group, int64_t topk_group, bool normalize, - const std::optional& mask, + const c10::optional& mask, const std::string& normed_by, const std::string& scoring_func, double route_scale, - const std::optional& e_score_correction_bias) { + const c10::optional& e_score_correction_bias) { torch::Tensor input_ = input.to(torch::kFloat32); auto reduce_weight = torch::empty({input.size(0), topk}, @@ -61,9 +61,9 @@ std::vector moe_gen_idx(torch::Tensor& expert_id, src_dst, dst_src, expert_sizes_gpu, - /*expert_mask=*/std::nullopt, - /*expert_sizes_cpu*/ std::nullopt, - /*expert_sizes_gpu*/ std::nullopt, + /*expert_mask=*/c10::nullopt, + /*expert_sizes_cpu*/ c10::nullopt, + /*expert_sizes_gpu*/ c10::nullopt, 0, expert_num, expert_num); @@ -90,8 +90,8 @@ torch::Tensor moe_combine_result(torch::Tensor& input, torch::Tensor& weight) { infer::moe_output_reduce_sum(output, input, weight, - /*mask=*/std::nullopt, - /*extra_residual*/ std::nullopt, + /*mask=*/c10::nullopt, + /*extra_residual*/ c10::nullopt, /*scaling_factor=*/1.0); return output; } diff --git a/ex_engine/csrc/ilu/group_gemm.cpp b/ex_engine/csrc/ilu/group_gemm.cpp index 38743e66..cd80dce5 100644 --- a/ex_engine/csrc/ilu/group_gemm.cpp +++ b/ex_engine/csrc/ilu/group_gemm.cpp @@ -20,7 +20,7 @@ namespace xllm::kernel::ilu { torch::Tensor group_gemm(torch::Tensor& input, torch::Tensor& weight, torch::Tensor& tokens_per_experts, - const std::optional& dst_to_src, + const c10::optional& dst_to_src, torch::Tensor& output) { infer::moe_w16a16_group_gemm( output, @@ -28,7 +28,7 @@ torch::Tensor group_gemm(torch::Tensor& input, weight, tokens_per_experts, dst_to_src, - /*bias=*/std::nullopt, + /*bias=*/c10::nullopt, /*format=*/"TN", /*persistent=*/0, /*output_n=*/tokens_per_experts.sum().item()); diff --git a/ex_engine/csrc/ilu/ixformer.h b/ex_engine/csrc/ilu/ixformer.h index 57ce66dc..6e3e215a 100644 --- a/ex_engine/csrc/ilu/ixformer.h +++ b/ex_engine/csrc/ilu/ixformer.h @@ -34,9 +34,9 @@ torch::Tensor ixinfer_flash_attn_unpad_with_block_tables( double scale, double softcap, bool sqrt_alibi, - const std::optional& alibi_slopes, - const std::optional& sinks, - std::optional& lse); + const c10::optional& alibi_slopes, + const c10::optional& sinks, + c10::optional& lse); void silu_and_mul(torch::Tensor& input, torch::Tensor& output); @@ -51,21 +51,21 @@ torch::Tensor xllm_paged_attention( torch::Tensor& context_lens, int64_t block_size, int64_t max_context_len, - const std::optional& alibi_slopes, + const c10::optional& alibi_slopes, bool causal, int32_t window_left, int32_t window_right, double softcap, bool enable_cuda_graph, bool use_sqrt_alibi, - const std::optional& sinks); + const c10::optional& sinks); torch::Tensor ixformer_linear(torch::Tensor& input, torch::Tensor& weight, int64_t act_type, - const std::optional& bias, - const std::optional& out, - const std::optional persistent); + const c10::optional& bias, + const c10::optional& out, + const c10::optional persistent); torch::Tensor ixformer_linear_ex(torch::Tensor& input, torch::Tensor& weight, @@ -92,7 +92,7 @@ void residual_rms_norm(torch::Tensor& input, torch::Tensor& weight, torch::Tensor& output, torch::Tensor& residual_output, - const std::optional& fused_bias, + const c10::optional& fused_bias, double alpha, double eps, bool is_post); @@ -100,7 +100,7 @@ void residual_rms_norm(torch::Tensor& input, void rms_norm(torch::Tensor& input, torch::Tensor& weight, torch::Tensor& output, - const std::optional& fused_bias, + const c10::optional& fused_bias, double eps); void topk_softmax(torch::Tensor& topk_weights, diff --git a/ex_engine/csrc/ilu/layer_attention.cpp b/ex_engine/csrc/ilu/layer_attention.cpp index b66f28a4..c5cc7049 100644 --- a/ex_engine/csrc/ilu/layer_attention.cpp +++ b/ex_engine/csrc/ilu/layer_attention.cpp @@ -62,13 +62,13 @@ AttentionImpl::AttentionImpl(int64_t num_heads, } } -std::tuple> AttentionImpl::forward( +std::tuple> AttentionImpl::forward( const AttentionMetadata& attn_metadata, torch::Tensor& query, torch::Tensor& key, torch::Tensor& value, KVCache& kv_cache) { - std::optional output_lse = std::nullopt; + c10::optional output_lse = c10::nullopt; torch::Tensor output; if (enable_mla_) { output = torch::empty({query.size(0), num_heads_ * v_head_dim_}, @@ -84,8 +84,8 @@ std::tuple> AttentionImpl::forward( attn_metadata.is_prefill || attn_metadata.is_chunked_prefill; int64_t num_kv_heads = (enable_mla_ && !only_prefill) ? 1 : num_kv_heads_; torch::Tensor k_cache = kv_cache.get_k_cache(); - std::optional v_cache; - std::optional v; + c10::optional v_cache; + c10::optional v; if (!enable_mla_) { v = value.view({-1, num_kv_heads, head_size_}); v_cache = kv_cache.get_v_cache(); @@ -118,10 +118,10 @@ void AttentionImpl::prefill_forward(torch::Tensor& query, torch::Tensor& value, torch::Tensor& output, const torch::Tensor& k_cache, - const std::optional& v_cache, + const c10::optional& v_cache, const AttentionMetadata& attn_metadata) { int64_t head_size_v = enable_mla_ ? v_head_dim_ : head_size_; - std::optional output_lse = std::nullopt; + c10::optional output_lse = c10::nullopt; query = query.view({-1, num_heads_, head_size_}); output = output.view({-1, num_heads_, head_size_v}); // torch::Tensor k_cache_ = k_cache; @@ -133,11 +133,11 @@ void AttentionImpl::prefill_forward(torch::Tensor& query, output_lse, attn_metadata.q_cu_seq_lens, attn_metadata.kv_cu_seq_lens, - /*alibi_slope=*/std::nullopt, - /*attn_bias=*/std::nullopt, - /*q_quant_scale=*/std::nullopt, - /*k_quant_scale=*/std::nullopt, - /*v_quant_scale=*/std::nullopt, + /*alibi_slope=*/c10::nullopt, + /*attn_bias=*/c10::nullopt, + /*q_quant_scale=*/c10::nullopt, + /*k_quant_scale=*/c10::nullopt, + /*v_quant_scale=*/c10::nullopt, attn_metadata.block_table, attn_metadata.max_query_len, attn_metadata.max_seq_len, @@ -152,12 +152,12 @@ void AttentionImpl::prefill_forward(torch::Tensor& query, void AttentionImpl::decoder_forward(torch::Tensor& query, torch::Tensor& output, const torch::Tensor& k_cache, - const std::optional& v_cache, + const c10::optional& v_cache, const AttentionMetadata& attn_metadata) { int64_t head_size_v = enable_mla_ ? v_head_dim_ : head_size_; query = query.view({-1, 1, num_heads_, head_size_}); output = output.view({-1, 1, num_heads_, head_size_v}); - std::optional output_lse = std::nullopt; + c10::optional output_lse = c10::nullopt; int64_t block_aligned_max_seq_len = attn_metadata.block_table.size(-1) * k_cache.size(2); @@ -169,11 +169,11 @@ void AttentionImpl::decoder_forward(torch::Tensor& query, attn_metadata.kv_seq_lens, v_cache, output_lse, - /*q_quant_scale=*/std::nullopt, - /*k_quant_scale=*/std::nullopt, - /*v_quant_scale=*/std::nullopt, - /*out_quant_scale=*/std::nullopt, - /*alibi_slope=*/std::nullopt, + /*q_quant_scale=*/c10::nullopt, + /*k_quant_scale=*/c10::nullopt, + /*v_quant_scale=*/c10::nullopt, + /*out_quant_scale=*/c10::nullopt, + /*alibi_slope=*/c10::nullopt, attn_metadata.attn_mask, attn_metadata.compute_dtype, block_aligned_max_seq_len, diff --git a/ex_engine/csrc/ilu/layer_attention.h b/ex_engine/csrc/ilu/layer_attention.h index a971835f..deb78c92 100644 --- a/ex_engine/csrc/ilu/layer_attention.h +++ b/ex_engine/csrc/ilu/layer_attention.h @@ -44,7 +44,7 @@ class AttentionImpl : public torch::nn::Module { bool enable_lighting_indexer, bool enable_mla); - std::tuple> forward( + std::tuple> forward( const AttentionMetadata& attn_metadata, torch::Tensor& query, torch::Tensor& key, @@ -56,13 +56,13 @@ class AttentionImpl : public torch::nn::Module { torch::Tensor& value, torch::Tensor& output, const torch::Tensor& k_cache, - const std::optional& v_cache, + const c10::optional& v_cache, const AttentionMetadata& attn_metadata); void decoder_forward(torch::Tensor& query, torch::Tensor& output, const torch::Tensor& k_cache, - const std::optional& v_cache, + const c10::optional& v_cache, const AttentionMetadata& attn_metadata); private: diff --git a/ex_engine/csrc/ilu/layer_fused_moe.cpp b/ex_engine/csrc/ilu/layer_fused_moe.cpp index 4238012e..20028ba3 100644 --- a/ex_engine/csrc/ilu/layer_fused_moe.cpp +++ b/ex_engine/csrc/ilu/layer_fused_moe.cpp @@ -296,7 +296,7 @@ torch::Tensor FusedMoEImpl::select_experts( SelectedExpertInfo& selected_expert_info, bool enable_all2all_communication) { // prepare the parameters for select_experts - std::optional e_score_correction_bias = std::nullopt; + c10::optional e_score_correction_bias = c10::nullopt; if (e_score_correction_bias_.defined()) { e_score_correction_bias = e_score_correction_bias_; } @@ -324,7 +324,7 @@ torch::Tensor FusedMoEImpl::select_experts( torch::Tensor gather_idx; torch::Tensor combine_idx; torch::Tensor token_count; - std::optional cusum_token_count; + c10::optional cusum_token_count; { xllm::kernel::MoeGenIdxParams moe_gen_idx_params; moe_gen_idx_params.expert_id = expert_id; @@ -337,7 +337,7 @@ torch::Tensor FusedMoEImpl::select_experts( // during all2all communication, we do not need cusum_token_count in the // following computation if (enable_all2all_communication) { - cusum_token_count = std::nullopt; + cusum_token_count = c10::nullopt; } else { cusum_token_count = output_vec[3]; } @@ -438,7 +438,7 @@ torch::Tensor FusedMoEImpl::forward_experts(const torch::Tensor& hidden_states, stream_initialized_ = true; } - std::optional e_score_correction_bias = std::nullopt; + c10::optional e_score_correction_bias = c10::nullopt; if (e_score_correction_bias_.defined()) { e_score_correction_bias = e_score_correction_bias_; } @@ -478,7 +478,7 @@ torch::Tensor FusedMoEImpl::forward_experts(const torch::Tensor& hidden_states, // 2. Process Result: Generate indices and unpack to computation buffer // use the buffer during initialization for the output expand_hidden_states = dispatch_recv_token_tensor_head_; - std::optional output_tail = std::nullopt; + c10::optional output_tail = c10::nullopt; if (is_smoothquant_) { output_tail = dispatch_recv_token_tensor_tail_; // update selected_expert_info with the tail (input scale) @@ -527,7 +527,7 @@ torch::Tensor FusedMoEImpl::forward_experts(const torch::Tensor& hidden_states, group_gemm_params.trans_b = true; group_gemm_params.a_quant_bit = is_smoothquant_ ? 8 : -1; group_gemm_params.output = gemm1_out; - group_gemm_params.combine_idx = std::nullopt; + group_gemm_params.combine_idx = c10::nullopt; gemm1_out = xllm::kernel::group_gemm(group_gemm_params); } @@ -639,7 +639,7 @@ torch::Tensor FusedMoEImpl::forward_experts(const torch::Tensor& hidden_states, // After group gemm is finished, some tensors are no // longer needed. We must explicitly release the memory. expand_hidden_states = torch::Tensor(); - selected_expert_info.input_scale = std::nullopt; + selected_expert_info.input_scale = c10::nullopt; act_out = torch::Tensor(); // Step 7: combine the intermediate results and get the final hidden states @@ -655,7 +655,7 @@ torch::Tensor FusedMoEImpl::forward_experts(const torch::Tensor& hidden_states, selected_expert_info.cusum_token_count; moe_combine_result_params.start_expert_id = start_expert_id_; moe_combine_result_params.expert_size = expert_size; - moe_combine_result_params.bias = std::nullopt; + moe_combine_result_params.bias = c10::nullopt; // if all2all communication is enabled and shared output is provided, // we will fused the add up to combine result if (enable_all2all_communication && n_shared_experts_ > 0) { diff --git a/ex_engine/csrc/ilu/layer_fused_moe.h b/ex_engine/csrc/ilu/layer_fused_moe.h index 3e477064..6335caf6 100644 --- a/ex_engine/csrc/ilu/layer_fused_moe.h +++ b/ex_engine/csrc/ilu/layer_fused_moe.h @@ -55,8 +55,8 @@ class FusedMoEImpl : public torch::nn::Module { torch::Tensor reduce_weight; torch::Tensor combine_idx; torch::Tensor token_count_slice; - std::optional cusum_token_count; - std::optional input_scale; + c10::optional cusum_token_count; + c10::optional input_scale; }; // initial steps for MoE computation, select the experts for each token diff --git a/ex_engine/csrc/ilu/matmul.cpp b/ex_engine/csrc/ilu/matmul.cpp index 618acf64..d2204ad5 100644 --- a/ex_engine/csrc/ilu/matmul.cpp +++ b/ex_engine/csrc/ilu/matmul.cpp @@ -43,7 +43,7 @@ bool gemv_conditions(const torch::Tensor& input, torch::Tensor matmul(torch::Tensor a, torch::Tensor b, - std::optional bias) { + c10::optional bias) { int64_t act_type = -1; bool persistent = false; std::vector output_shape = a.sizes().vec(); diff --git a/ex_engine/csrc/ilu/norm.cpp b/ex_engine/csrc/ilu/norm.cpp index c5a98595..7d972b57 100644 --- a/ex_engine/csrc/ilu/norm.cpp +++ b/ex_engine/csrc/ilu/norm.cpp @@ -22,10 +22,10 @@ namespace xllm::kernel::ilu { void residual_layer_norm(torch::Tensor& input, torch::Tensor& output, - std::optional& residual, + c10::optional& residual, torch::Tensor& weight, - std::optional& bias, - std::optional& residual_out, + c10::optional& bias, + c10::optional& residual_out, double eps) { auto residual_ = residual.value_or(torch::zeros_like(input)); torch::Tensor residual_out_ = residual_out.value_or(torch::zeros_like(input)); @@ -44,7 +44,7 @@ void rms_norm(torch::Tensor& output, torch::Tensor& input, torch::Tensor& weight, double eps) { - std::optional fused_bias = std::nullopt; + c10::optional fused_bias = c10::nullopt; infer::rms_norm(input, weight, output, fused_bias, eps); } diff --git a/ex_engine/csrc/ilu/qwen3_gated_delta_net_base.cpp b/ex_engine/csrc/ilu/qwen3_gated_delta_net_base.cpp index cec9a95e..ed9e50d3 100644 --- a/ex_engine/csrc/ilu/qwen3_gated_delta_net_base.cpp +++ b/ex_engine/csrc/ilu/qwen3_gated_delta_net_base.cpp @@ -34,7 +34,7 @@ std::tuple torch_recurrent_gated_delta_rule( torch::Tensor value, torch::Tensor g, torch::Tensor beta, - std::optional initial_state, + c10::optional initial_state, bool output_final_state = true, bool use_qk_l2norm_in_kernel = true) { auto initial_dtype = query.dtype(); @@ -390,8 +390,8 @@ torch::Tensor Qwen3GatedDeltaNetBaseImpl::forward( conv1d_params.weight = conv_weight; conv1d_params.conv_state_indices = linear_state_indices; conv1d_params.block_idx_last_scheduled_token = - std::optional(); - conv1d_params.initial_state_idx = std::optional(); + c10::optional(); + conv1d_params.initial_state_idx = c10::optional(); conv1d_params.query_start_loc = attn_metadata.q_cu_seq_lens; conv1d_params.max_query_len = attn_metadata.max_query_len; mixed_qkv = xllm::kernel::causal_conv1d_update(conv1d_params);