-
Notifications
You must be signed in to change notification settings - Fork 173
fix(BA-5967): pre-validate slot types in sokovan validator chain #11515
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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Reject session requests whose image or caller declares a resource slot the target resource group does not provide, returning a clear 4xx instead of failing internally. |
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
63 changes: 63 additions & 0 deletions
63
src/ai/backend/manager/sokovan/scheduling_controller/validators/image_slot_type_rule.py
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,63 @@ | ||
| """Image-declared slot-type compatibility validator. | ||
|
|
||
| Every slot key declared in an image's ``resource_spec`` must be served | ||
| by some non-terminated agent in the requested resource group. The | ||
| context's ``known_slot_types`` is sourced from | ||
| ``agent_resources`` joined with ``agents`` (status != TERMINATED) and | ||
| ``resource_slot_types``, so it reflects the RG's hardware inventory and | ||
| the registered unit metadata in one mapping. | ||
|
|
||
| When the RG has no non-terminated agents the request is rejected | ||
| outright — an empty inventory cannot satisfy any image declaration and | ||
| would otherwise let the session reach the scheduler only to fail there. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from ai.backend.manager.data.session.spec import SessionSpec | ||
| from ai.backend.manager.errors.api import InvalidAPIParameters | ||
| from ai.backend.manager.sokovan.scheduling_controller.validators.session_spec_base import ( | ||
| SessionSpecValidationContext, | ||
| SessionSpecValidatorRule, | ||
| ) | ||
|
|
||
|
|
||
| class ImageSlotTypeRule(SessionSpecValidatorRule): | ||
| """Image-declared slot keys must be served by an agent in the target RG.""" | ||
|
|
||
| def name(self) -> str: | ||
| return "image_slot_type" | ||
|
|
||
| def validate( | ||
| self, | ||
| spec: SessionSpec, | ||
| context: SessionSpecValidationContext, | ||
| ) -> None: | ||
| rg_slot_types = context.known_slot_types | ||
| if not rg_slot_types: | ||
| raise InvalidAPIParameters( | ||
| extra_msg=( | ||
| f"resource group '{spec.scope.resource_group_name}' has no " | ||
| f"agents serving any resource slot." | ||
| ), | ||
| ) | ||
| for idx, kernel in enumerate(spec.kernel_specs): | ||
| image_info = context.image_infos.get(kernel.execution_spec.image_id) | ||
| if image_info is None: | ||
| continue | ||
| unknown = sorted( | ||
| slot_name | ||
| for slot_name in image_info.resource_spec | ||
| if slot_name not in rg_slot_types | ||
| ) | ||
| if unknown: | ||
| raise InvalidAPIParameters( | ||
| extra_msg=( | ||
| f"kernel_specs[{idx}]: image '{image_info.canonical}' " | ||
| f"requires resource slot(s) {unknown} that resource " | ||
| f"group '{spec.scope.resource_group_name}' does not " | ||
| f"serve. Pick an image whose required slots are " | ||
| f"available here, or switch to a resource group that " | ||
| f"supports these slots." | ||
| ), | ||
| ) |
60 changes: 60 additions & 0 deletions
60
src/ai/backend/manager/sokovan/scheduling_controller/validators/requested_slot_type_rule.py
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,60 @@ | ||
| """User-requested slot-type compatibility validator. | ||
|
|
||
| Every ``resource_type`` in a kernel's requested resource list must be | ||
| served by some non-terminated agent in the requested resource group. | ||
| The context's ``known_slot_types`` is sourced from ``agent_resources`` | ||
| joined with ``agents`` (status != TERMINATED) and | ||
| ``resource_slot_types``, so it reflects the RG's hardware inventory and | ||
| the registered unit metadata in one mapping. | ||
|
|
||
| When the RG has no non-terminated agents the request is rejected | ||
| outright — an empty inventory cannot satisfy any caller-supplied | ||
| request and would otherwise let the session reach the scheduler only | ||
| to fail there. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from ai.backend.manager.data.session.spec import SessionSpec | ||
| from ai.backend.manager.errors.api import InvalidAPIParameters | ||
| from ai.backend.manager.sokovan.scheduling_controller.validators.session_spec_base import ( | ||
| SessionSpecValidationContext, | ||
| SessionSpecValidatorRule, | ||
| ) | ||
|
|
||
|
|
||
| class RequestedSlotTypeRule(SessionSpecValidatorRule): | ||
| """Requested slot keys must be served by an agent in the target RG.""" | ||
|
|
||
| def name(self) -> str: | ||
| return "requested_slot_type" | ||
|
|
||
| def validate( | ||
| self, | ||
| spec: SessionSpec, | ||
| context: SessionSpecValidationContext, | ||
| ) -> None: | ||
| rg_slot_types = context.known_slot_types | ||
| if not rg_slot_types: | ||
| raise InvalidAPIParameters( | ||
| extra_msg=( | ||
| f"resource group '{spec.scope.resource_group_name}' has no " | ||
| f"agents serving any resource slot." | ||
| ), | ||
| ) | ||
| for idx, kernel in enumerate(spec.kernel_specs): | ||
| unknown = sorted({ | ||
| entry.resource_type | ||
| for entry in kernel.execution_spec.resources | ||
| if entry.resource_type not in rg_slot_types | ||
| }) | ||
| if unknown: | ||
| raise InvalidAPIParameters( | ||
| extra_msg=( | ||
| f"kernel_specs[{idx}]: the request asks for resource " | ||
| f"slot(s) {unknown} that resource group " | ||
| f"'{spec.scope.resource_group_name}' does not serve. " | ||
| f"Drop these slots from the request or switch to a " | ||
| f"resource group that supports them." | ||
| ), | ||
| ) | ||
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
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.
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.
Why not including kernel row id instead of kernel_specs[{idx}]?