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
16 changes: 12 additions & 4 deletions fastdeploy/model_executor/layers/sample/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,18 @@ def gather_logprobs(
else:
indices = token_ids
top_logprobs = token_logprobs
indices = indices.cpu()
top_logprobs = top_logprobs.cpu()
token_ranks = token_ranks.cpu()
return LogprobsTensors(indices, top_logprobs, token_ranks)
if current_platform.is_cuda():
indices_cpu = paddle.empty_like(indices, device="cpu").pin_memory()
top_logprobs_cpu = paddle.empty_like(top_logprobs, device="cpu").pin_memory()
token_ranks_cpu = paddle.empty_like(token_ranks, device="cpu").pin_memory()
indices_cpu.copy_(indices, False)
top_logprobs_cpu.copy_(top_logprobs, False)
token_ranks_cpu.copy_(token_ranks, False)
else:
indices_cpu = indices.cpu()
top_logprobs_cpu = top_logprobs.cpu()
token_ranks_cpu = token_ranks.cpu()
return LogprobsTensors(indices_cpu, top_logprobs_cpu, token_ranks_cpu)

def forward_cuda(
self,
Expand Down
2 changes: 1 addition & 1 deletion fastdeploy/model_executor/pre_and_post_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def save_output_normal(
sampler_output, model_output.index_to_batch_id, model_output.enable_pd_reorder
)
save_output_topk(
sampler_output.sampled_token_ids,
share_inputs["sampled_token_ids"],
sampler_output.logprobs_tensors.logprob_token_ids,
sampler_output.logprobs_tensors.logprobs,
sampler_output.logprobs_tensors.selected_token_ranks,
Expand Down
2 changes: 2 additions & 0 deletions fastdeploy/worker/gpu_model_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3119,6 +3119,8 @@ def _get_prompt_logprobs_list(
token_ids, logprobs, ranks = self.sampler.gather_logprobs(
raw_logprobs, num_prompt_logprobs, prompt_token_ids_tensor
)
# Synchronize before using token_ids, logprobs and ranks to ensure async copy are completed.
paddle.device.synchronize()
chunk_slice = slice(start_idx, start_idx + num_logits)
logprobs_tensors.logprob_token_ids[chunk_slice].copy_(token_ids, False)
logprobs_tensors.logprobs[chunk_slice].copy_(logprobs, False)
Expand Down
6 changes: 3 additions & 3 deletions fastdeploy/worker/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ def slice_rows(self, start: int, end: int):
"""
with paddle.no_grad():
return LogprobsTensors(
paddle.to_tensor(self.logprob_token_ids[start:end], place=self.logprob_token_ids.place),
paddle.to_tensor(self.logprobs[start:end], place=self.logprob_token_ids.place),
paddle.to_tensor(self.selected_token_ranks[start:end], place=self.logprob_token_ids.place),
paddle.to_tensor(self.logprob_token_ids.cpu()[start:end], place="cpu"),
paddle.to_tensor(self.logprobs.cpu()[start:end], place="cpu"),
paddle.to_tensor(self.selected_token_ranks.cpu()[start:end], place="cpu"),
)


Expand Down
Loading