-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Add MCP integration #80
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
Open
Yuvrajxms09
wants to merge
3
commits into
firstbatchxyz:master
Choose a base branch
from
Yuvrajxms09:feat/mcp-integration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import os | ||
| from dnet.utils.logger import logger | ||
| from dnet.utils.model import get_model_config_json | ||
| from distilp.profiler import profile_model | ||
| from dnet.core.types.topology import TopologyInfo | ||
| from .models import APILoadModelResponse, UnloadModelResponse | ||
|
|
||
|
|
||
| async def get_api_callback_address( | ||
| cluster_manager, | ||
| grpc_port: int | str, | ||
| ) -> str: | ||
| api_props = await cluster_manager.discovery.async_get_own_properties() | ||
| grpc_port_int = int(grpc_port) | ||
| api_callback_addr = (os.getenv("DNET_API_CALLBACK_ADDR") or "").strip() | ||
| if not api_callback_addr: | ||
| api_callback_addr = f"{api_props.local_ip}:{grpc_port_int}" | ||
| if api_props.local_ip in ("127.0.0.1", "localhost"): | ||
| logger.warning( | ||
| "API callback address is loopback (%s). Remote shards will fail to SendToken. " | ||
| "Set DNET_API_CALLBACK_ADDR to a reachable host:port.", | ||
| api_callback_addr, | ||
| ) | ||
| return api_callback_addr | ||
|
|
||
|
|
||
| async def _prepare_topology_core( | ||
| cluster_manager, | ||
| model: str, | ||
| kv_bits: str, | ||
| seq_len: int, | ||
| progress_callback=None, | ||
| ) -> TopologyInfo: | ||
| model_config = get_model_config_json(model) | ||
| embedding_size = int(model_config["hidden_size"]) | ||
| num_layers = int(model_config["num_hidden_layers"]) | ||
|
|
||
| await cluster_manager.scan_devices() | ||
| if progress_callback: | ||
| await progress_callback("Profiling cluster performance") | ||
| batch_sizes = [1] | ||
| profiles = await cluster_manager.profile_cluster( | ||
| model, embedding_size, 2, batch_sizes | ||
| ) | ||
| if not profiles: | ||
| raise RuntimeError("No profiles collected") | ||
|
|
||
| if progress_callback: | ||
| await progress_callback("Computing optimal layer distribution") | ||
| model_profile_split = profile_model( | ||
| repo_id=model, | ||
| batch_sizes=batch_sizes, | ||
| sequence_length=seq_len, | ||
| ) | ||
| model_profile = model_profile_split.to_model_profile() | ||
|
|
||
| topology = await cluster_manager.solve_topology( | ||
| profiles, model_profile, model, num_layers, kv_bits | ||
| ) | ||
| return topology | ||
|
|
||
|
|
||
| async def _load_model_core( | ||
| cluster_manager, | ||
| model_manager, | ||
| inference_manager, | ||
| topology: TopologyInfo, | ||
| ) -> APILoadModelResponse: | ||
| api_props = await cluster_manager.discovery.async_get_own_properties() | ||
| grpc_port = int(inference_manager.grpc_port) | ||
|
|
||
| api_callback_addr = await get_api_callback_address( | ||
| cluster_manager, inference_manager.grpc_port | ||
| ) | ||
| response = await model_manager.load_model( | ||
| topology, | ||
| api_props, | ||
| grpc_port, | ||
| api_callback_address=api_callback_addr, | ||
| ) | ||
| if response.success: | ||
| first_shard = topology.devices[0] | ||
| await inference_manager.connect_to_ring( | ||
| first_shard.local_ip, first_shard.shard_port, api_callback_addr | ||
| ) | ||
| return response | ||
|
|
||
|
|
||
| async def _unload_model_core( | ||
| cluster_manager, | ||
| model_manager, | ||
| ) -> UnloadModelResponse: | ||
| await cluster_manager.scan_devices() | ||
| shards = cluster_manager.shards | ||
| response = await model_manager.unload_model(shards) | ||
| if response.success: | ||
| cluster_manager.current_topology = None | ||
| return response |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.