[Infefficient design] ModelRunnerCpp - optionally return Tensor instead of List
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.7k
- Forks
- 2.8k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 489
Description
It seems that the current design is a little inefficient, especially as it relates to implementing speculative sampling using Draft-Target-Model. Please feel to correct me if I'm misunderstanding somewhere.
The current example for Draft-Target-Model requires doing this in a loop:
- Run inference with
max_draft_tokensfor draft model, and get thedraft_tokens(i.e.output_token_ids) - Run inference for
max_draft_tokens+1for target model, providing thedraft_tokensin theExternalDraftTokensConfig
The issue here is that the CPU doesn't really need to know what the draft_tokens are (except if calculating acceptance rate, maybe?), and we should be able to pass the draft_tokens to the target model without a CUDA synchronize (if running on the same GPU).
But, right now, ModelRunnerCpp uses executor.await_responses() ( here ). Each response actually contains a list of output tokens instead of a Tensor (output_token_ids), which seems to trigger a CUDA sync.
For DTM, given that max_draft_tokens is limited there are a lot of loops. This further means that the loop that DTM spec sampling needs to run in requires a CUDA sync for every iteration. In my experiments, the CUDA syncs are causing ~90% of the latency during inference time.
Can this API be amended to optionally return a Tensor/pointer/is that even possible/am I misunderstanding the whole problem?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.