-
Notifications
You must be signed in to change notification settings - Fork 34
integration test for weight sync that actually tests behavior #217
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
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e89a339
integration test for weight sync that actually tests behavior
casteryh d5ba56f
logging
casteryh ee7eea1
a
casteryh 368286b
better diagnostics
casteryh 0f2d8a1
avoid dtensor yoga, setting everything to zero
casteryh 092bcba
add sanity check
casteryh 6b5b148
Merge branch 'main' into weight-sync-test
casteryh 0ec0d0d
fix merge conflicts
casteryh 086d27c
Merge branch 'main' into weight-sync-test
casteryh 564b4f2
lint
casteryh 28dd912
addressing reviewer feedback
casteryh f2f489e
revert gitignore
casteryh cc79d9b
revert gitignore
casteryh 6a4a160
Merge branch 'main' into weight-sync-test
casteryh 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,6 @@ | |
| from __future__ import annotations | ||
|
|
||
| import asyncio | ||
|
|
||
| import logging | ||
| import os | ||
| import sys | ||
|
|
@@ -392,15 +391,6 @@ async def update_weights(self, policy_version: int): | |
| self.policy_version = policy_version | ||
| logger.info(f"Weight update completed (now v{self.policy_version})") | ||
|
|
||
| @endpoint | ||
| async def _get_model_params(self) -> dict[str, torch.Tensor]: | ||
| """Get the current model parameters. Only for testing purposes.""" | ||
| val_mesh = await self.policy_worker._get_model_params.call() | ||
| sharded_state_dicts = {} | ||
| for idx, val in val_mesh.items(): | ||
| sharded_state_dicts[idx["gpus"]] = val | ||
| return sharded_state_dicts | ||
|
|
||
| @endpoint | ||
| async def get_version(self) -> int: | ||
| """Get the current policy version.""" | ||
|
|
@@ -410,6 +400,18 @@ async def get_version(self) -> int: | |
| async def stop(self): | ||
| self.running = False | ||
|
|
||
| @endpoint | ||
| async def _test_save_model_params(self): | ||
| """Save model parameters before weight update, used for tesing purposes only.""" | ||
| logger.info("[Policy] start saving model parameters before update for testing") | ||
casteryh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| await self.policy_worker._test_save_model_params.call() | ||
|
|
||
| @endpoint | ||
| async def _test_validate_model_params(self, validate_fn): | ||
| """Validate updated model params using validate_fn.""" | ||
| logger.info("[Policy] start validating model parameters post update") | ||
casteryh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return await self.policy_worker._test_validate_model_params.call(validate_fn) | ||
|
|
||
|
Comment on lines
410
to
414
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really smart! Having the |
||
| def _to_completions(self, request_output: RequestOutput) -> list[Completion]: | ||
| """Convert a RequestOutput to a list of Completion objects.""" | ||
| completions = [] | ||
|
|
@@ -453,6 +455,9 @@ class PolicyWorker(ForgeActor): | |
| state_dict_key: str = "model_state_dict" | ||
| use_dcp: bool = True | ||
|
|
||
| # used for tesing purposes only | ||
| _test_prev_params = {} | ||
|
|
||
| def __post_init__(self): | ||
| super().__init__() | ||
|
|
||
|
|
@@ -545,15 +550,25 @@ async def setup_kv_cache(self): | |
| return kv_cache_config | ||
|
|
||
| @endpoint | ||
| async def _get_model_params(self) -> dict[str, torch.Tensor]: | ||
| model = self.worker.model_runner.model | ||
| state_dict = {} | ||
| async def _test_save_model_params(self): | ||
| """Save model parameters before weight update, used for tesing purposes only.""" | ||
| logger.info( | ||
| "[PolicyWorker] start saving model parameters before update for testing" | ||
casteryh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
| for name, param in self.worker.model_runner.model.named_parameters(): | ||
| self._test_prev_params[name] = param.detach().cpu() | ||
| logger.info( | ||
| "[PolicyWorker] finished saving model parameters, len = %d", | ||
| len(self._test_prev_params), | ||
| ) | ||
|
|
||
| for name, param in model.named_parameters(): | ||
| if "layers.0" not in name: | ||
| continue | ||
| state_dict[name] = param.cpu().detach() | ||
| return state_dict | ||
| @endpoint | ||
| async def _test_validate_model_params(self, validate_fn): | ||
| """Validate updated model params using validate_fn.""" | ||
| logger.info("[PolicyWorker] start validating model parameters post update") | ||
casteryh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return validate_fn( | ||
| self._test_prev_params, self.worker.model_runner.model, logger | ||
| ) | ||
|
|
||
| def setup_worker(self): | ||
| """Build and Instantiate vLLM worker""" | ||
|
|
||
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,5 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. |
Oops, something went wrong.
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.