Skip to content

Conversation

@JustinTong0323
Copy link
Collaborator

Motivation

Add support for https://github.com/ServerlessLLM/ServerlessLLM

cc @future-xy @SecretSettler

Modifications

Accuracy Tests

Benchmarking and Profiling

Checklist

- Introduced 'serverless_llm' as a new load format option.
- Added methods to save and load Serverless LLM model states in the model runner and loader.
- Updated relevant classes and configurations to accommodate the new model loading mechanism.

Signed-off-by: Xinyuan Tong <[email protected]>
Signed-off-by: Xinyuan Tong <[email protected]>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @JustinTong0323, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request integrates support for the serverless_llm model weight format, allowing the system to load and save models using the ServerlessLLM checkpoint store. This enhancement provides greater flexibility in managing and deploying large language models by enabling seamless interaction with the ServerlessLLM infrastructure.

Highlights

  • New Load Format Support: Added SERVERLESS_LLM as a new option to the LoadFormat enum, enabling the system to recognize and handle models stored in the ServerlessLLM format.
  • ServerlessLLM Model Loader Implementation: Introduced a dedicated ServerlessLLMModelLoader class, which provides comprehensive logic for loading and saving model weights from/to the ServerlessLLM checkpoint store, including handling tensor parallelism and device mapping.
  • Model State Saving Functionality: Implemented new methods (save_serverless_llm_state) across the Engine, Scheduler, and ModelRunner components to facilitate saving the current model's state in the ServerlessLLM format via remote procedure calls.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for the serverless_llm format loader, enabling the system to load and save model states from ServerlessLLM checkpoint stores. The changes are well-integrated across various components, including the LoadFormat enum, Engine API, Scheduler mixin, and ModelRunner. A new ServerlessLLMModelLoader class is implemented, mirroring the behavior of existing loaders like ShardedStateLoader for handling sharded tensors and managing model state. The implementation includes necessary utility methods for filtering subtensors, managing device maps, and ensuring all parameters are correctly loaded and saved. Overall, the changes are logical and extend the system's capabilities effectively.

Comment on lines +303 to +332
def _filter_subtensors(tensors: Dict[str, torch.Tensor]) -> Dict[str, torch.Tensor]:
"""Filter out view/sub-tensors that share storage with other tensors."""
same_storage_groups: Dict[Any, List[Tuple[str, torch.Tensor]]] = (
collections.defaultdict(list)
)
for key, tensor in tensors.items():
if tensor.numel():
ptr = tensor.untyped_storage().data_ptr()
same_storage_groups[tensor.device, ptr].append((key, tensor))

def get_end_ptr(tensor: torch.Tensor) -> int:
return tensor.view(-1)[-1].data_ptr() + tensor.element_size()

result: Dict[str, torch.Tensor] = {}
for group in same_storage_groups.values():
for k, t in group:
a, b = t.data_ptr(), get_end_ptr(t)
for k2, t2 in group:
if not t2.is_contiguous():
continue
a2, b2 = t2.data_ptr(), get_end_ptr(t2)
if a < a2 or b2 < b:
continue
if a2 < a or b < b2 or not t.is_contiguous():
break
if k2 < k:
break
else:
result[k] = t
return result
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The _filter_subtensors method is duplicated here from ShardedStateLoader. To improve maintainability and reduce code duplication, consider extracting this common utility into a shared helper function or a base class method if applicable. 1

Rules References

Footnotes

  1. Avoid code duplication to improve maintainability and reduce the risk of inconsistencies when changes are needed.

Signed-off-by: Xinyuan Tong <[email protected]>
- Added try-except blocks around the import of load_dict and its usage to log errors if the import fails or if loading the model state dictionary encounters issues.
- Improved logging messages to guide users on potential installation or server issues.

Signed-off-by: Xinyuan Tong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants