Beispiel #1
0
    def train_status(self, request: PluginRequest[TrainStatusPluginInput],
                     model: ThirdPartyModel) -> Response[TrainPluginOutput]:
        """Since trainable can't be assumed to be asynchronous, the trainer is responsible for uploading its own model file."""
        logging.debug(f"train {request}")

        # Create a Response object at the top with a Task attached. This will let us stream back updates
        # TODO: This is very non-intuitive. We should improve this.
        response = Response(status=Task(task_id=request.task_id))

        # Call train status
        train_plugin_output = model.train_status(request.data)

        if train_plugin_output.training_complete:
            # Save the model with the `default` handle.
            archive_path_in_steamship = model.save_remote(
                client=self.client,
                plugin_instance_id=request.plugin_instance_id)

            # Set the model location on the plugin output.
            train_plugin_output.archive_path = archive_path_in_steamship

        # Set the response on the `data` field of the object
        response.set_data(json=train_plugin_output)
        logging.info(response.dict(by_alias=True))
        return response
Beispiel #2
0
    def train(self, request: PluginRequest[TrainPluginInput],
              model: ThirdPartyModel) -> Response[TrainPluginOutput]:
        """Since trainable can't be assumed to be asynchronous, the trainer is responsible for uploading its own model file."""
        logging.debug(f"train {request}")

        # Create a Response object at the top with a Task attached. This will let us stream back updates
        # TODO: This is very non-intuitive. We should improve this.
        response = Response(status=Task(task_id=request.task_id))

        # Train the model
        train_plugin_input = request.data
        train_plugin_output = model.train(train_plugin_input)

        # Set the response on the `data` field of the object
        response.set_data(json=train_plugin_output)
        logging.info(response.dict(by_alias=True))
        return response