This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[Retiarii] Pure-python execution engine #3605
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4cf8cfd
Initiate branch
ultmaster cf3ca49
Add context stack util
ultmaster 55edabf
Support and graph and mutator ends
ultmaster b583202
Add experiment and corresponding pytorch support
ultmaster 5e98874
Add test for submit model
ultmaster d2761d0
Disable py-exec test for staging
ultmaster 236c890
Add high-level API tests (failing)
ultmaster 9b52869
Highlevel API test passed
ultmaster 47cfc87
FInish end-to-end tests
ultmaster d9546f7
Suppress F821
ultmaster 6e27ffb
Fix test for engine
ultmaster e4ec2a2
Fix mutation history tests
ultmaster 2d0cd6a
Add docs
ultmaster 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 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 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 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 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 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,53 @@ | ||
from typing import Dict, Any, List | ||
|
||
from ..graph import Evaluator, Model | ||
from ..integration_api import receive_trial_parameters | ||
from ..utils import ContextStack, import_, get_importable_name | ||
from .base import BaseExecutionEngine | ||
|
||
|
||
class PythonGraphData: | ||
def __init__(self, class_name: str, init_parameters: Dict[str, Any], | ||
mutation: Dict[str, Any], evaluator: Evaluator) -> None: | ||
self.class_name = class_name | ||
self.init_parameters = init_parameters | ||
self.mutation = mutation | ||
self.evaluator = evaluator | ||
|
||
def dump(self) -> dict: | ||
return { | ||
'class_name': self.class_name, | ||
'init_parameters': self.init_parameters, | ||
'mutation': self.mutation, | ||
'evaluator': self.evaluator | ||
} | ||
|
||
@staticmethod | ||
def load(data) -> 'PythonGraphData': | ||
return PythonGraphData(data['class_name'], data['init_parameters'], data['mutation'], data['evaluator']) | ||
|
||
|
||
class PurePythonExecutionEngine(BaseExecutionEngine): | ||
@classmethod | ||
def pack_model_data(cls, model: Model) -> Any: | ||
mutation = {mut.mutator.label: _unpack_if_only_one(mut.samples) for mut in model.history} | ||
graph_data = PythonGraphData(get_importable_name(model.python_class, relocate_module=True), | ||
model.python_init_params, mutation, model.evaluator) | ||
return graph_data | ||
|
||
@classmethod | ||
def trial_execute_graph(cls) -> None: | ||
graph_data = PythonGraphData.load(receive_trial_parameters()) | ||
|
||
class _model(import_(graph_data.class_name)): | ||
def __init__(self): | ||
super().__init__(**graph_data.init_parameters) | ||
|
||
with ContextStack('fixed', graph_data.mutation): | ||
graph_data.evaluator._execute(_model) | ||
|
||
|
||
def _unpack_if_only_one(ele: List[Any]): | ||
if len(ele) == 1: | ||
return ele[0] | ||
return ele |
This file contains 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 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.
终于可以不用torchscript了,大佬牛逼