-
Notifications
You must be signed in to change notification settings - Fork 123
Add --availability-model to truss train update #2634
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
johnnt849
wants to merge
3
commits into
main
Choose a base branch
from
claude/truss-queued-job-updates-793747
base: main
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
|
|
||
| from truss.cli.train import core as train_cli | ||
| from truss_train.definitions import AvailabilityModel | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_remote(): | ||
| remote = MagicMock() | ||
| remote.api = MagicMock() | ||
| return remote | ||
|
|
||
|
|
||
| class TestUpdateTrainingJob: | ||
| """Test cases for the update_training_job function.""" | ||
|
|
||
| def test_update_training_job_success(self, mock_remote): | ||
| """Test updating a training job with a specific job ID.""" | ||
| mock_remote.api.search_training_jobs.return_value = [ | ||
| { | ||
| "id": "test_job_123", | ||
| "training_project": {"id": "project_456", "name": "test-project"}, | ||
| } | ||
| ] | ||
| mock_remote.api.update_training_job.return_value = { | ||
| "id": "test_job_123", | ||
| "priority": 42, | ||
| "training_project": {"id": "project_456", "name": "test-project"}, | ||
| } | ||
|
|
||
| result = train_cli.update_training_job( | ||
| remote_provider=mock_remote, job_id="test_job_123", priority=42 | ||
| ) | ||
|
|
||
| assert result["id"] == "test_job_123" | ||
| assert result["priority"] == 42 | ||
|
|
||
| mock_remote.api.search_training_jobs.assert_called_once_with( | ||
| job_id="test_job_123" | ||
| ) | ||
| mock_remote.api.update_training_job.assert_called_once_with( | ||
| "project_456", "test_job_123", priority=42, availability_model=None | ||
| ) | ||
|
|
||
| def test_update_training_job_availability_model(self, mock_remote): | ||
| """The availability model is passed to the API as its wire value.""" | ||
| mock_remote.api.search_training_jobs.return_value = [ | ||
| { | ||
| "id": "test_job_123", | ||
| "training_project": {"id": "project_456", "name": "test-project"}, | ||
| } | ||
| ] | ||
| mock_remote.api.update_training_job.return_value = {"id": "test_job_123"} | ||
|
|
||
| train_cli.update_training_job( | ||
| remote_provider=mock_remote, | ||
| job_id="test_job_123", | ||
| availability_model=AvailabilityModel.SPOT, | ||
| ) | ||
|
|
||
| mock_remote.api.update_training_job.assert_called_once_with( | ||
| "project_456", "test_job_123", priority=None, availability_model="spot" | ||
| ) | ||
|
|
||
| def test_update_training_job_priority_and_availability_model(self, mock_remote): | ||
| """Both fields are forwarded together when both are provided.""" | ||
| mock_remote.api.search_training_jobs.return_value = [ | ||
| { | ||
| "id": "test_job_123", | ||
| "training_project": {"id": "project_456", "name": "test-project"}, | ||
| } | ||
| ] | ||
| mock_remote.api.update_training_job.return_value = {"id": "test_job_123"} | ||
|
|
||
| train_cli.update_training_job( | ||
| remote_provider=mock_remote, | ||
| job_id="test_job_123", | ||
| priority=7, | ||
| availability_model=AvailabilityModel.DEDICATED, | ||
| ) | ||
|
|
||
| mock_remote.api.update_training_job.assert_called_once_with( | ||
| "project_456", "test_job_123", priority=7, availability_model="dedicated" | ||
| ) | ||
|
|
||
| def test_update_training_job_no_job_found(self, mock_remote): | ||
| """Test updating a non-existent job ID.""" | ||
| mock_remote.api.search_training_jobs.return_value = [] | ||
|
|
||
| with pytest.raises( | ||
| RuntimeError, match="No training job found with ID: nonexistent_job" | ||
| ): | ||
| train_cli.update_training_job( | ||
| remote_provider=mock_remote, job_id="nonexistent_job", priority=42 | ||
| ) | ||
|
|
||
| mock_remote.api.update_training_job.assert_not_called() | ||
|
|
||
| def test_update_training_job_no_fields_raises(self, mock_remote): | ||
| """Test that updating with no fields provided raises an error.""" | ||
| with pytest.raises( | ||
| ValueError, match="At least one field to update must be provided" | ||
| ): | ||
| train_cli.update_training_job( | ||
| remote_provider=mock_remote, job_id="test_job_123" | ||
| ) | ||
|
|
||
| mock_remote.api.search_training_jobs.assert_not_called() | ||
| mock_remote.api.update_training_job.assert_not_called() |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting reminder to also add this to https://github.com/basetenlabs/baseten-cli (unless you want to)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add a PR for that in a bit!