fix(build): std::optional -> c10::optional in ALL ilu/ files including ixformer.h

This commit is contained in:
claude
2026-08-11 07:40:42 +00:00
parent f944ef912b
commit c31a749143
11 changed files with 77 additions and 77 deletions

View File

@@ -23,9 +23,9 @@ using namespace ixformer;
namespace xllm::kernel::ilu {
void reshape_paged_cache(torch::Tensor& key,
std::optional<torch::Tensor>& value,
c10::optional<torch::Tensor>& value,
torch::Tensor& key_cache,
std::optional<torch::Tensor>& value_cache,
c10::optional<torch::Tensor>& 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<torch::Tensor>& value,
const c10::optional<torch::Tensor>& value,
torch::Tensor& output,
std::optional<torch::Tensor>& output_lse,
const std::optional<torch::Tensor>& q_cu_seq_lens,
const std::optional<torch::Tensor>& kv_cu_seq_lens,
const std::optional<torch::Tensor>& alibi_slope,
const std::optional<torch::Tensor>& attn_bias,
const std::optional<torch::Tensor>& q_quant_scale,
const std::optional<torch::Tensor>& k_quant_scale,
const std::optional<torch::Tensor>& v_quant_scale,
c10::optional<torch::Tensor>& output_lse,
const c10::optional<torch::Tensor>& q_cu_seq_lens,
const c10::optional<torch::Tensor>& kv_cu_seq_lens,
const c10::optional<torch::Tensor>& alibi_slope,
const c10::optional<torch::Tensor>& attn_bias,
const c10::optional<torch::Tensor>& q_quant_scale,
const c10::optional<torch::Tensor>& k_quant_scale,
const c10::optional<torch::Tensor>& 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<torch::Tensor>& v_cache,
std::optional<torch::Tensor>& output_lse,
const std::optional<torch::Tensor>& q_quant_scale,
const std::optional<torch::Tensor>& k_cache_quant_scale,
const std::optional<torch::Tensor>& v_cache_quant_scale,
const std::optional<torch::Tensor>& out_quant_scale,
const std::optional<torch::Tensor>& alibi_slope,
const std::optional<torch::Tensor>& mask,
const c10::optional<torch::Tensor>& v_cache,
c10::optional<torch::Tensor>& output_lse,
const c10::optional<torch::Tensor>& q_quant_scale,
const c10::optional<torch::Tensor>& k_cache_quant_scale,
const c10::optional<torch::Tensor>& v_cache_quant_scale,
const c10::optional<torch::Tensor>& out_quant_scale,
const c10::optional<torch::Tensor>& alibi_slope,
const c10::optional<torch::Tensor>& mask,
const std::string& compute_dtype,
int64_t max_seq_len,
int64_t window_size_left,

View File

@@ -25,11 +25,11 @@ std::tuple<torch::Tensor, torch::Tensor> moe_active_topk(
int64_t num_expert_group,
int64_t topk_group,
bool normalize,
const std::optional<torch::Tensor>& mask,
const c10::optional<torch::Tensor>& mask,
const std::string& normed_by,
const std::string& scoring_func,
double route_scale,
const std::optional<torch::Tensor>& e_score_correction_bias) {
const c10::optional<torch::Tensor>& 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<torch::Tensor> 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;
}

View File

@@ -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<torch::Tensor>& dst_to_src,
const c10::optional<torch::Tensor>& 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<int64_t>());

View File

@@ -34,9 +34,9 @@ torch::Tensor ixinfer_flash_attn_unpad_with_block_tables(
double scale,
double softcap,
bool sqrt_alibi,
const std::optional<torch::Tensor>& alibi_slopes,
const std::optional<torch::Tensor>& sinks,
std::optional<torch::Tensor>& lse);
const c10::optional<torch::Tensor>& alibi_slopes,
const c10::optional<torch::Tensor>& sinks,
c10::optional<torch::Tensor>& 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<torch::Tensor>& alibi_slopes,
const c10::optional<torch::Tensor>& 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<torch::Tensor>& sinks);
const c10::optional<torch::Tensor>& sinks);
torch::Tensor ixformer_linear(torch::Tensor& input,
torch::Tensor& weight,
int64_t act_type,
const std::optional<torch::Tensor>& bias,
const std::optional<torch::Tensor>& out,
const std::optional<bool> persistent);
const c10::optional<torch::Tensor>& bias,
const c10::optional<torch::Tensor>& out,
const c10::optional<bool> 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<torch::Tensor>& fused_bias,
const c10::optional<torch::Tensor>& 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<torch::Tensor>& fused_bias,
const c10::optional<torch::Tensor>& fused_bias,
double eps);
void topk_softmax(torch::Tensor& topk_weights,

View File

@@ -62,13 +62,13 @@ AttentionImpl::AttentionImpl(int64_t num_heads,
}
}
std::tuple<torch::Tensor, std::optional<torch::Tensor>> AttentionImpl::forward(
std::tuple<torch::Tensor, c10::optional<torch::Tensor>> AttentionImpl::forward(
const AttentionMetadata& attn_metadata,
torch::Tensor& query,
torch::Tensor& key,
torch::Tensor& value,
KVCache& kv_cache) {
std::optional<torch::Tensor> output_lse = std::nullopt;
c10::optional<torch::Tensor> 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<torch::Tensor, std::optional<torch::Tensor>> 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<torch::Tensor> v_cache;
std::optional<torch::Tensor> v;
c10::optional<torch::Tensor> v_cache;
c10::optional<torch::Tensor> 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<torch::Tensor>& v_cache,
const c10::optional<torch::Tensor>& v_cache,
const AttentionMetadata& attn_metadata) {
int64_t head_size_v = enable_mla_ ? v_head_dim_ : head_size_;
std::optional<torch::Tensor> output_lse = std::nullopt;
c10::optional<torch::Tensor> 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<torch::Tensor>& v_cache,
const c10::optional<torch::Tensor>& 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<torch::Tensor> output_lse = std::nullopt;
c10::optional<torch::Tensor> 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,

View File

@@ -44,7 +44,7 @@ class AttentionImpl : public torch::nn::Module {
bool enable_lighting_indexer,
bool enable_mla);
std::tuple<torch::Tensor, std::optional<torch::Tensor>> forward(
std::tuple<torch::Tensor, c10::optional<torch::Tensor>> 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<torch::Tensor>& v_cache,
const c10::optional<torch::Tensor>& v_cache,
const AttentionMetadata& attn_metadata);
void decoder_forward(torch::Tensor& query,
torch::Tensor& output,
const torch::Tensor& k_cache,
const std::optional<torch::Tensor>& v_cache,
const c10::optional<torch::Tensor>& v_cache,
const AttentionMetadata& attn_metadata);
private:

View File

@@ -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<torch::Tensor> e_score_correction_bias = std::nullopt;
c10::optional<torch::Tensor> 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<torch::Tensor> cusum_token_count;
c10::optional<torch::Tensor> 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<torch::Tensor> e_score_correction_bias = std::nullopt;
c10::optional<torch::Tensor> 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<torch::Tensor> output_tail = std::nullopt;
c10::optional<torch::Tensor> 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) {

View File

@@ -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<torch::Tensor> cusum_token_count;
std::optional<torch::Tensor> input_scale;
c10::optional<torch::Tensor> cusum_token_count;
c10::optional<torch::Tensor> input_scale;
};
// initial steps for MoE computation, select the experts for each token

View File

@@ -43,7 +43,7 @@ bool gemv_conditions(const torch::Tensor& input,
torch::Tensor matmul(torch::Tensor a,
torch::Tensor b,
std::optional<torch::Tensor> bias) {
c10::optional<torch::Tensor> bias) {
int64_t act_type = -1;
bool persistent = false;
std::vector<int64_t> output_shape = a.sizes().vec();

View File

@@ -22,10 +22,10 @@ namespace xllm::kernel::ilu {
void residual_layer_norm(torch::Tensor& input,
torch::Tensor& output,
std::optional<torch::Tensor>& residual,
c10::optional<torch::Tensor>& residual,
torch::Tensor& weight,
std::optional<torch::Tensor>& bias,
std::optional<torch::Tensor>& residual_out,
c10::optional<torch::Tensor>& bias,
c10::optional<torch::Tensor>& 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<torch::Tensor> fused_bias = std::nullopt;
c10::optional<torch::Tensor> fused_bias = c10::nullopt;
infer::rms_norm(input, weight, output, fused_bias, eps);
}

View File

@@ -34,7 +34,7 @@ std::tuple<torch::Tensor, torch::Tensor> torch_recurrent_gated_delta_rule(
torch::Tensor value,
torch::Tensor g,
torch::Tensor beta,
std::optional<torch::Tensor> initial_state,
c10::optional<torch::Tensor> 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<torch::Tensor>();
conv1d_params.initial_state_idx = std::optional<torch::Tensor>();
c10::optional<torch::Tensor>();
conv1d_params.initial_state_idx = c10::optional<torch::Tensor>();
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);