Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion csrc/api/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ STABLE_TORCH_LIBRARY(_flashmla_C, m) {
m.def("sparse_prefill_fwd(Tensor q, Tensor kv, Tensor indices, float sm_scale, int d_v, Tensor? attn_sink, Tensor? topk_length, Tensor(a!)? out_) -> Tensor[]");
m.def("dense_prefill_fwd(Tensor workspace_buffer, Tensor q, Tensor k, Tensor v, Tensor cumulative_seqlen_q, Tensor cumulative_seqlen_kv, Tensor(a!) o, Tensor(b!) lse, int mask_mode_code, float softmax_scale, int max_seqlen_q, int max_seqlen_kv, bool is_varlen) -> ()");
m.def("fused_norm_rope_attn_rope_cast_fwd(Tensor q, Tensor kv, Tensor indices, float sm_scale, int d_v, Tensor? attn_sink, Tensor? topk_length, bool enable_q_norm, float rms_norm_eps, Tensor token_positions, bool is_rope_neox_style, int rope_dim, Tensor cos_sin_cache, int n_wv_group, int num_per_channels, bool use_tma_aligned_col_major_sf, bool round_sf, bool use_packed_ue8m0, Tensor(d!)? out_fp8=None, Tensor(e!)? out_sf=None) -> Tensor[]");
m.def("fused_norm_rope_attn_rope_cast_decode(Tensor q, Tensor kv, Tensor indices, float sm_scale, int d_v, Tensor? attn_sink, Tensor? topk_length, Tensor? extra_kv, Tensor? extra_indices, Tensor? extra_topk_length, bool enable_q_norm, float rms_norm_eps, Tensor token_positions, bool is_rope_neox_style, int rope_dim, Tensor cos_sin_cache, int n_wv_group, int num_per_channels, bool use_tma_aligned_col_major_sf, bool round_sf, bool use_packed_ue8m0, Tensor(d!)? out_fp8=None, Tensor(e!)? out_sf=None) -> Tensor[]");
m.def("fused_norm_rope_attn_rope_cast_decode(Tensor q, Tensor kv, Tensor indices, float sm_scale, int d_v, Tensor? attn_sink, Tensor? topk_length, Tensor? extra_kv, Tensor? extra_indices, Tensor? extra_topk_length, bool enable_q_norm, float rms_norm_eps, Tensor token_positions, bool is_rope_neox_style, int rope_dim, Tensor cos_sin_cache, int n_wv_group, int num_per_channels, bool use_tma_aligned_col_major_sf, bool round_sf, bool use_packed_ue8m0, Tensor(d!)? out_fp8=None, Tensor(e!)? out_sf=None, int mega_num_splits=1, Tensor(f!)? mega_o_accum=None, Tensor(g!)? mega_lse_accum=None) -> Tensor[]");
m.def("permute_q_b_proj(Tensor q_b_proj, Tensor scale_factors, int h_q, int d_q) -> Tensor[]");
m.def("permute_wv_proj(Tensor wv_proj, Tensor scale_factors, int wv_group_size, int d_o) -> Tensor[]");
#ifdef FLASH_MLA_ENABLE_DENSE_BWD
Expand Down
20 changes: 18 additions & 2 deletions csrc/api/fused_norm_rope_attn_rope_cast_fwd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,10 @@ std::vector<Tensor> fused_norm_rope_attn_rope_cast_decode(
bool round_sf,
bool use_packed_ue8m0,
const std::optional<Tensor> &out_fp8_,
const std::optional<Tensor> &out_sf_
const std::optional<Tensor> &out_sf_,
int64_t mega_num_splits,
const std::optional<Tensor> &mega_o_accum_,
const std::optional<Tensor> &mega_lse_accum_
) {
Arch arch = Arch();
STD_TORCH_CHECK(arch.is_sm100f(), "Fused Norm + RoPE + Core Attn + RoPE + Cast (fused_norm_rope_attn_rope_cast_decode) is only supported on SM100f architectures.");
Expand Down Expand Up @@ -457,8 +460,21 @@ std::vector<Tensor> fused_norm_rope_attn_rope_cast_decode(
(fp8_e4m3*)out_fp8.data_ptr(),
(uint32_t*)out_sf.data_ptr(),
(uint32_t)int64_stride_to_int(out_sf.stride(1)),
(uint32_t)int64_stride_to_int(out_sf.stride(2))
(uint32_t)int64_stride_to_int(out_sf.stride(2)),

(uint32_t)mega_num_splits,
mega_o_accum_.has_value() ? (float*)mega_o_accum_.value().data_ptr() : nullptr,
mega_lse_accum_.has_value() ? (float*)mega_lse_accum_.value().data_ptr() : nullptr,
mega_o_accum_.has_value() ? (uint32_t)int64_stride_to_int(mega_o_accum_.value().stride(0)) : 0u,
mega_lse_accum_.has_value() ? (uint32_t)int64_stride_to_int(mega_lse_accum_.value().stride(0)) : 0u
};
if (mega_o_accum_.has_value() || mega_lse_accum_.has_value()) {
STD_TORCH_CHECK(h_q == 64, "the fp32-partial mega decode path currently requires h_q == 64");
STD_TORCH_CHECK(mega_o_accum_.has_value() && mega_lse_accum_.has_value(),
"mega_o_accum and mega_lse_accum must be given together");
}
STD_TORCH_CHECK(mega_num_splits == 1 || mega_o_accum_.has_value(),
"mega_num_splits > 1 requires the fp32 partial buffers");

DISPATCH_NUM_HEADS(h_q, H_Q, ([&]() {
DISPATCH_BOOLEAN_FLAG(enable_q_norm, ENABLE_Q_NORM, ([&]() {
Expand Down
5 changes: 4 additions & 1 deletion csrc/api/interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ std::vector<Tensor> fused_norm_rope_attn_rope_cast_decode(
bool round_sf,
bool use_packed_ue8m0,
const std::optional<Tensor> &out_fp8_,
const std::optional<Tensor> &out_sf_);
const std::optional<Tensor> &out_sf_,
int64_t mega_num_splits,
const std::optional<Tensor> &mega_o_accum_,
const std::optional<Tensor> &mega_lse_accum_);

std::vector<Tensor> permute_q_b_proj(
const Tensor &q_b_proj,
Expand Down
Loading