-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Implement resource requirements for components #194
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
Copilot
wants to merge
29
commits into
main
Choose a base branch
from
copilot/implement-resource-requirements
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
29 commits
Select commit
Hold shift + click to select a range
4530341
Initial plan
Copilot d529dee
Add Resource class and integrate with Component, RayProcess, and Tuner
Copilot f59376c
Add comprehensive tests for Resource implementation
Copilot 0219833
Add examples for resource requirements in Ray processes
Copilot 3ec7854
Fix type annotations and address code review feedback
Copilot 9515154
Address code review feedback: generalize suffixes, make memory intege…
Copilot c400a97
Move suffixes to top
toby-coleman a38aa88
Rework logic for tune placement bundles
toby-coleman 573a0e1
Merge remote-tracking branch 'origin/main' into copilot/implement-res…
toby-coleman 31092ab
Docs config improved for schemas
toby-coleman 6bf7017
Tidy up documentation on resources example
toby-coleman bae7c46
Add resources for smoke tests
toby-coleman a9a4ef5
Make sure resources are available in runner
toby-coleman c14cbaf
Remove non-existent cross refs in docs
toby-coleman 2588544
Fixup types
toby-coleman d2e7aa2
Test that actor is passed the resource requirements
toby-coleman 3301419
Increase timeouts on test CI
toby-coleman 9b361df
Typing
toby-coleman d7c87c6
Fixup test
toby-coleman a3c9555
Increase tuner test timeout
toby-coleman c9aa1ce
Correct format for placement groups in Ray tune
toby-coleman 155c571
Typo
toby-coleman a562b88
Coverage
toby-coleman 5fb86bc
refactor: Resource value validation
chrisk314 b0fd414
fix: Inconsistent type annotation syntax
chrisk314 3f8031f
Allows declaring resources at Component declaration time
chrisk314 82a76cf
Enhances tests
chrisk314 2892fe9
Ignore lint error
chrisk314 ea310c1
Update docs and examples to show class-level resource declaration
Copilot 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| ::: plugboard.schemas | ||
| ::: plugboard_schemas |
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,47 @@ | ||
| # Example YAML configuration with resource requirements | ||
| # | ||
| # This configuration demonstrates how to specify resource requirements | ||
| # for components in a Plugboard process. Resources can be specified as: | ||
| # - Numerical values: cpu: 2.0 | ||
| # - Milli-units: cpu: "250m" (equals 0.25) | ||
| # - Memory units: memory: "100Mi" (equals 100 * 1024 * 1024 bytes) | ||
| # | ||
| # Note: Resources can be declared at the component class level (recommended) | ||
| # or overridden in the YAML configuration as shown below. | ||
| plugboard: | ||
| process: | ||
| type: plugboard.process.RayProcess | ||
| connector_builder: | ||
| type: plugboard.connector.RayConnector | ||
| args: | ||
| name: resource-example-process | ||
| components: | ||
| - type: examples.tutorials.004_using_ray.resources_example.DataProducer | ||
| args: | ||
| name: producer | ||
| iters: 10 | ||
| resources: | ||
| cpu: 1.0 # (1)! | ||
| - type: examples.tutorials.004_using_ray.resources_example.CPUIntensiveTask | ||
| args: | ||
| name: cpu-task | ||
| # CPUIntensiveTask has class-level resources (cpu: 2.0) | ||
| # Override to use more memory | ||
| resources: | ||
| cpu: 2.0 # (2)! | ||
| memory: "512Mi" # (3)! | ||
| - type: examples.tutorials.004_using_ray.resources_example.GPUTask | ||
| args: | ||
| name: gpu-task | ||
| # GPUTask has class-level resources (cpu: "500m", gpu: 1) | ||
| # Can override or extend with custom resources | ||
| resources: | ||
| cpu: "500m" # (4)! | ||
| gpu: 1 # (5)! | ||
| resources: | ||
| custom_hardware: 2 # (6)! | ||
| connectors: | ||
| - source: producer.output | ||
| target: cpu-task.x | ||
| - source: cpu-task.y | ||
| target: gpu-task.data | ||
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,95 @@ | ||
| """Example demonstrating resource requirements for components in RayProcess.""" | ||
|
|
||
| import asyncio | ||
| import typing as _t | ||
|
|
||
| import ray | ||
|
|
||
| from plugboard.component import Component, IOController as IO | ||
| from plugboard.connector import RayConnector | ||
| from plugboard.process import RayProcess | ||
| from plugboard.schemas import ComponentArgsDict, ConnectorSpec, Resource | ||
|
|
||
|
|
||
| class CPUIntensiveTask(Component): | ||
| """Component that requires more CPU resources. | ||
|
|
||
| Resource requirements are declared as a class attribute. | ||
| """ | ||
|
|
||
| io = IO(inputs=["x"], outputs=["y"]) | ||
| resources = Resource(cpu=2.0) # Declare resources at class level | ||
|
|
||
| async def step(self) -> None: | ||
| """Execute CPU-intensive computation.""" | ||
| # Simulate CPU-intensive work | ||
| result = sum(i**2 for i in range(int(self.x * 10000))) | ||
| self.y = result | ||
|
|
||
|
|
||
| class GPUTask(Component): | ||
| """Component that requires GPU resources. | ||
|
|
||
| Resource requirements are declared as a class attribute. | ||
| """ | ||
|
|
||
| io = IO(inputs=["data"], outputs=["result"]) | ||
| resources = Resource(cpu="500m", gpu=1) # Declare resources at class level | ||
|
|
||
| async def step(self) -> None: | ||
| """Execute GPU computation.""" | ||
| # Simulate GPU computation | ||
| self.result = self.data * 2 | ||
|
|
||
|
|
||
| class DataProducer(Component): | ||
| """Produces data for processing.""" | ||
|
|
||
| io = IO(outputs=["output"]) | ||
|
|
||
| def __init__(self, iters: int, **kwargs: _t.Unpack[ComponentArgsDict]) -> None: | ||
| """Initialize DataProducer with iteration count.""" | ||
| super().__init__(**kwargs) | ||
| self._iters = iters | ||
|
|
||
| async def init(self) -> None: | ||
| """Initialize the data sequence.""" | ||
| self._seq = iter(range(self._iters)) | ||
|
|
||
| async def step(self) -> None: | ||
| """Produce the next data value.""" | ||
| try: | ||
| self.output = next(self._seq) | ||
| except StopIteration: | ||
| await self.io.close() | ||
|
|
||
|
|
||
| async def main() -> None: | ||
| """Run the process with resource-constrained components.""" | ||
| # --8<-- [start:resources] | ||
| # Resources can be declared at the class level (see CPUIntensiveTask and GPUTask above) | ||
| # or overridden when instantiating components | ||
| process = RayProcess( | ||
| components=[ | ||
| DataProducer(name="producer", iters=5), # Uses default resources | ||
| CPUIntensiveTask(name="cpu-task"), # Uses class-level resources (2.0 CPU) | ||
| GPUTask(name="gpu-task"), # Uses class-level resources (0.5 CPU, 1 GPU) | ||
| ], | ||
| connectors=[ | ||
| RayConnector(spec=ConnectorSpec(source="producer.output", target="cpu-task.x")), | ||
| RayConnector(spec=ConnectorSpec(source="cpu-task.y", target="gpu-task.data")), | ||
| ], | ||
| ) | ||
| # --8<-- [end:resources] | ||
|
|
||
| async with process: | ||
| await process.run() | ||
|
|
||
| print("Process completed successfully!") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| if not ray.is_initialized(): | ||
| # Ray must be initialised with the necessary resources | ||
| ray.init(num_cpus=5, num_gpus=1, resources={"custom_hardware": 10}, include_dashboard=True) | ||
| asyncio.run(main()) |
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.
Uh oh!
There was an error while loading. Please reload this page.