Пример #1
0
 def _build_executable_spec(
     self, node_id: str,
     spec: any_pb2.Any) -> local_deployment_config_pb2.ExecutableSpec:
   """Builds ExecutableSpec given the any proto from IntermediateDeploymentConfig."""
   result = local_deployment_config_pb2.ExecutableSpec()
   if spec.Is(result.python_class_executable_spec.DESCRIPTOR):
     spec.Unpack(result.python_class_executable_spec)
   elif spec.Is(result.container_executable_spec.DESCRIPTOR):
     spec.Unpack(result.container_executable_spec)
   else:
     raise ValueError(
         'executor spec of {} is expected to be of one of the '
         'types of tfx.orchestration.deployment_config.ExecutableSpec.spec '
         'but got type {}'.format(node_id, spec.type_url))
   return result
Пример #2
0
def _build_local_platform_config(
        node_id: str,
        spec: any_pb2.Any) -> local_deployment_config_pb2.LocalPlatformConfig:
    """Builds LocalPlatformConfig given the any proto from IntermediateDeploymentConfig."""
    result = local_deployment_config_pb2.LocalPlatformConfig()
    if spec.Is(result.docker_platform_config.DESCRIPTOR):
        spec.Unpack(result.docker_platform_config)
    else:
        raise ValueError(
            'Platform config of {} is expected to be of one of the types of '
            'tfx.orchestration.deployment_config.LocalPlatformConfig.config '
            'but got type {}'.format(node_id, spec.type_url))
    return result
Пример #3
0
def unpack(data: GrpcAny, message: GrpcMessage) -> None:
    """Unpack the serialized protocol buffer message.

    Args:
        data (:obj:`google.protobuf.message.Any`): the serialized protocol buffer message.
        message (:obj:`google.protobuf.message.Message`): the protocol buffer message object
            to which the response data is deserialized.

    Raises:
        ValueError: message is not protocol buffer message object or message's type is not
            matched with the response data type
    """
    if not isinstance(message, GrpcMessage):
        raise ValueError(
            'output message is not protocol buffer message object')
    if not data.Is(message.DESCRIPTOR):
        raise ValueError(
            f'invalid type. serialized message type: {data.type_url}')
    data.Unpack(message)