Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Torch deepseek v2 #1621

Merged
merged 32 commits into from
Jun 24, 2024
Merged
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions lmdeploy/pytorch/engine/model_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ def __get_free_gpu_mem_size(cache_block_size: int):
f' {runtime_cache_size>>20} mb')
return gpu_mem_physical_free * cache_config.cache_max_entry_count

def __adjust_block_size():
"""adjust block_size."""
# TODO: support kernel with both large head dim and large block size.
if model_config.k_head_dim >= 512 and cache_config.block_size > 32:
cache_config.block_size = 32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this affect models other than DeepSeek v2?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the mha kernel needs enough smem to cache the kv_cache block and query block. Any model with such a large head_dim should be limited.
Among all the models that Pytorch engine has supported, only deepseek v2 with MLA implementation meets the condition.

rank = 0
if dist.is_initialized():
rank = dist.get_rank()
if rank == 0:
logger.warning(
f'Update `block_size={cache_config.block_size}`'
f' for large `head_dim={model_config.k_head_dim}`.')

__adjust_block_size()

cache_block_size = CacheEngine.get_cache_block_size(
cache_config.block_size, model_config, world_size)
gpu_mem = __get_free_gpu_mem_size(cache_block_size)
Expand Down
Loading