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

[release] update torch_tune_serve_test to use anyscale connect #16754

Merged
merged 4 commits into from
Jul 7, 2021
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
Prev Previous commit
Next Next commit
use download_results to download model checkpoint
  • Loading branch information
matthewdeng committed Jul 2, 2021
commit 55dc78fc9cb8a93e0eea4d8889624ded78e1fb49
33 changes: 29 additions & 4 deletions release/golden_notebook_tests/workloads/torch_tune_serve_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,34 @@ def train_mnist(test_mode=False, num_workers=1, use_gpu=False):
checkpoint_at_end=True)


def get_best_model(best_model_checkpoint_path):
model_state = torch.load(best_model_checkpoint_path)
def get_remote_model(remote_model_checkpoint_path):
address = os.environ.get("RAY_ADDRESS")
if address is not None and address.startswith("anyscale:https://"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this also work with the Ray OSS client?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, for OSS this would go to the else block and use ray.remote to fetch the model. I updated the code with some better path isolation and successfully ran this script on a Ray cluster!

# Download training results to local client.
local_dir = "~/ray_results"
# TODO(matt): remove the following line when Anyscale Connect
# supports tilde expansion.
local_dir = os.path.expanduser(local_dir)
remote_dir = "/home/ray/ray_results/"
ray.client().download_results(
local_dir=local_dir, remote_dir=remote_dir)

# Compute local path.
rel_model_checkpoint_path = os.path.relpath(
remote_model_checkpoint_path, remote_dir)
local_model_checkpoint_path = os.path.join(local_dir,
rel_model_checkpoint_path)

# Load model reference.
return get_model(local_model_checkpoint_path)
else:
get_best_model_remote = ray.remote(get_model)
return ray.get(
get_best_model_remote.remote(remote_model_checkpoint_path))


def get_model(model_checkpoint_path):
model_state = torch.load(model_checkpoint_path)

model = ResNet18(None)
model.conv1 = nn.Conv2d(
Expand Down Expand Up @@ -189,8 +215,7 @@ def test_predictions(test_mode=False):

print("Retrieving best model.")
best_checkpoint = analysis.best_checkpoint
get_best_model_remote = ray.remote(get_best_model)
model_id = ray.get(get_best_model_remote.remote(best_checkpoint))
model_id = get_remote_model(best_checkpoint)

print("Setting up Serve.")
setup_serve(model_id)
Expand Down