-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Temporary] tensorflow plugin implementation (#141)
- Loading branch information
Showing
7 changed files
with
345 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
from __future__ import absolute_import | ||
|
||
try: | ||
from inspect import getfullargspec as _getargspec | ||
except ImportError: | ||
from inspect import getargspec as _getargspec | ||
|
||
import six as _six | ||
from flytekit.common import constants as _constants | ||
from flytekit.common.exceptions import scopes as _exception_scopes | ||
from flytekit.common.tasks import output as _task_output, sdk_runnable as _sdk_runnable | ||
from flytekit.common.types import helpers as _type_helpers | ||
from flytekit.models import literals as _literal_models, task as _task_models | ||
from google.protobuf.json_format import MessageToDict as _MessageToDict | ||
|
||
|
||
class SdkRunnableTensorflowContainer(_sdk_runnable.SdkRunnableContainer): | ||
|
||
@property | ||
def args(self): | ||
""" | ||
Override args to remove the injection of command prefixes | ||
:rtype: list[Text] | ||
""" | ||
return self._args | ||
|
||
class SdkTensorFlowTask(_sdk_runnable.SdkRunnableTask): | ||
def __init__( | ||
self, | ||
task_function, | ||
task_type, | ||
discovery_version, | ||
retries, | ||
interruptible, | ||
deprecated, | ||
discoverable, | ||
timeout, | ||
workers_count, | ||
ps_replicas_count, | ||
chief_replicas_count, | ||
per_replica_storage_request, | ||
per_replica_cpu_request, | ||
per_replica_gpu_request, | ||
per_replica_memory_request, | ||
per_replica_storage_limit, | ||
per_replica_cpu_limit, | ||
per_replica_gpu_limit, | ||
per_replica_memory_limit, | ||
environment | ||
): | ||
tensorflow_job = _task_models.TensorFlowJob( | ||
workers_count=workers_count, | ||
ps_replicas_count=ps_replicas_count, | ||
chief_replicas_count=chief_replicas_count | ||
).to_flyte_idl() | ||
super(SdkTensorFlowTask, self).__init__( | ||
task_function=task_function, | ||
task_type=task_type, | ||
discovery_version=discovery_version, | ||
retries=retries, | ||
interruptible=interruptible, | ||
deprecated=deprecated, | ||
storage_request=per_replica_storage_request, | ||
cpu_request=per_replica_cpu_request, | ||
gpu_request=per_replica_gpu_request, | ||
memory_request=per_replica_memory_request, | ||
storage_limit=per_replica_storage_limit, | ||
cpu_limit=per_replica_cpu_limit, | ||
gpu_limit=per_replica_gpu_limit, | ||
memory_limit=per_replica_memory_limit, | ||
discoverable=discoverable, | ||
timeout=timeout, | ||
environment=environment, | ||
custom=_MessageToDict(tensorflow_job) | ||
) | ||
|
||
def _get_container_definition( | ||
self, | ||
**kwargs | ||
): | ||
""" | ||
:rtype: SdkRunnableTensorflowContainer | ||
""" | ||
return super(SdkTensorFlowTask, self)._get_container_definition(cls=SdkRunnableTensorflowContainer, **kwargs) |
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,51 @@ | ||
from __future__ import absolute_import | ||
from flytekit.sdk.tasks import tensorflow_task, inputs, outputs | ||
from flytekit.sdk.types import Types | ||
from flytekit.common import constants as _common_constants | ||
from flytekit.common.tasks import sdk_runnable as _sdk_runnable, tensorflow_task as _tensorflow_task | ||
from flytekit.models import types as _type_models | ||
from flytekit.models.core import identifier as _identifier | ||
import datetime as _datetime | ||
|
||
|
||
@inputs(in1=Types.Integer) | ||
@outputs(out1=Types.String) | ||
@tensorflow_task(workers_count=2, ps_replicas_count=1, chief_replicas_count=1) | ||
def simple_tensorflow_task(wf_params, sc, in1, out1): | ||
pass | ||
|
||
|
||
simple_tensorflow_task._id = _identifier.Identifier(_identifier.ResourceType.TASK, "project", "domain", "name", "version") | ||
|
||
|
||
def test_simple_tensorflow_task(): | ||
assert isinstance(simple_tensorflow_task, _tensorflow_task.SdkTensorFlowTask) | ||
assert isinstance(simple_tensorflow_task, _sdk_runnable.SdkRunnableTask) | ||
assert simple_tensorflow_task.interface.inputs['in1'].description == '' | ||
assert simple_tensorflow_task.interface.inputs['in1'].type == \ | ||
_type_models.LiteralType(simple=_type_models.SimpleType.INTEGER) | ||
assert simple_tensorflow_task.interface.outputs['out1'].description == '' | ||
assert simple_tensorflow_task.interface.outputs['out1'].type == \ | ||
_type_models.LiteralType(simple=_type_models.SimpleType.STRING) | ||
assert simple_tensorflow_task.type == _common_constants.SdkTaskType.TENSORFLOW_TASK | ||
assert simple_tensorflow_task.task_function_name == 'simple_tensorflow_task' | ||
assert simple_tensorflow_task.task_module == __name__ | ||
assert simple_tensorflow_task.metadata.timeout == _datetime.timedelta(seconds=0) | ||
assert simple_tensorflow_task.metadata.deprecated_error_message == '' | ||
assert simple_tensorflow_task.metadata.discoverable is False | ||
assert simple_tensorflow_task.metadata.discovery_version == '' | ||
assert simple_tensorflow_task.metadata.retries.retries == 0 | ||
assert len(simple_tensorflow_task.container.resources.limits) == 0 | ||
assert len(simple_tensorflow_task.container.resources.requests) == 0 | ||
assert simple_tensorflow_task.custom['workers'] == 2 | ||
assert simple_tensorflow_task.custom['psReplicas'] == 1 | ||
assert simple_tensorflow_task.custom['chiefReplicas'] == 1 | ||
|
||
|
||
# Should strip out the venv component of the args. | ||
assert simple_tensorflow_task._get_container_definition().args[0] == 'pyflyte-execute' | ||
|
||
pb2 = simple_tensorflow_task.to_flyte_idl() | ||
assert pb2.custom['workers'] == 2 | ||
assert pb2.custom['psReplicas'] == 1 | ||
assert pb2.custom['chiefReplicas'] == 1 |