Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,16 @@ void GetBlockShapeAndSplitKVBlock(
// Note (sunxin): Skip capturing the DtoH copy (it's time-consuming); CPU data
// is only for branching in attention.
#ifndef PADDLE_WITH_CUSTOM_DEVICE_METAX_GPU
if (!phi::backends::gpu::IsCUDAGraphCapturing())
#endif
if (!phi::backends::gpu::IsCUDAGraphCapturing()) {
max_len_tensor_cpu.copy_(
max_len_tensor_gpu, max_len_tensor_cpu.place(), false);
cudaStreamSynchronize(stream);
}
#else
max_len_tensor_cpu.copy_(
max_len_tensor_gpu, max_len_tensor_cpu.place(), false);
cudaStreamSynchronize(stream);
#endif

auto max_len_cpu_ptr = max_len_tensor_cpu.data<int>();
int max_len_this_time = max_len_cpu_ptr[0];
Expand Down Expand Up @@ -435,6 +441,12 @@ void GetBlockShapeAndSplitKVBlock(
encoder_num_blocks_x_cpu.copy_(
encoder_num_blocks_x, encoder_num_blocks_x_cpu.place(), false);
}
#ifndef PADDLE_WITH_CUSTOM_DEVICE_METAX_GPU
if (!phi::backends::gpu::IsCUDAGraphCapturing())
cudaStreamSynchronize(stream);
#else
cudaStreamSynchronize(stream);
#endif
}

std::vector<std::vector<int64_t>> GetBlockShapeAndSplitKVBlockInferShape(
Expand Down
17 changes: 17 additions & 0 deletions custom_ops/gpu_ops/flash_mask_attn/mainloop_attn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,23 @@ struct CollectiveMainloopAttn {

softmax.rescale_o(tOrO, scores_scale);
consumer_wait(pipeline_v, smem_pipe_read_v);
if (seq_len_k - n_block * kBlockN < kBlockN) {
int valid_k = seq_len_k - n_block * kBlockN;
auto sVt_this = sVt(_, _, smem_pipe_read_v.index());
constexpr int kHdLo = decltype(get<0, 0>(shape(sVt_this)))::value;
constexpr int kHdHi = decltype(get<0, 1>(shape(sVt_this)))::value;
if (thread_idx >= valid_k && thread_idx < kBlockN) {
#pragma unroll
for (int hd_hi = 0; hd_hi < kHdHi; ++hd_hi) {
#pragma unroll
for (int hd_lo = 0; hd_lo < kHdLo; ++hd_lo) {
sVt_this(make_coord(make_coord(hd_lo, hd_hi), thread_idx)) =
Element(0);
}
}
}
cutlass::arch::fence_view_async_shared();
}
gemm</*zero_init=*/false, /*wg_wait=*/-1>(
tiled_mma1, tOrP, tOrV(_, _, _, smem_pipe_read_v.index()), tOrO);
warp_scheduler_barrier_arrive();
Expand Down
Loading