Container-Based Function Creation
Container-Based Function Creation
Container-Based Function Creation
Container-based functions require building and pushing a Cloud Functions compatible Docker container image to your container registry.
Example containers can be found in the examples repository.
The repository also contains helper functions that are useful when authoring your container, including:
It’s always a best practice to emit logs from your inference container. Cloud Functions supports third-party logging and metrics emission from your container.
Please note that container functions should not run as root user, running as root is not formally supported on any Cloud Functions backend.
Any server can be implemented within the container, as long as it implements the following:
These endpoints are expected to be served on the same port, defined as the inferencePort.
Cloud Functions reserves the following ports on your container for internal monitoring and metrics:
80808010Cloud Functions also expects the following directories in the container to remain read-only for caching purposes:
/config/ directory/config/It’s possible to use any container with Cloud Functions as long as it implements a server with the above endpoints. The below is an example of a FastAPI-based container compatible with Cloud Functions. Clone the FastAPI echo example.
Note in the example above, the function’s configuration during creation will be:
/echo/health8000See the [Create the Function] section below for the remaining steps.
NVIDIA’s PyTriton is a Python native solution of Triton inference server. A minimum version of 0.3.0 is required.
requirements.txt file.Here is an example of a requirements.txt file:
run.py file (or similar Python file) needs to define a PyTriton model.__init__ function, an _infer_fn function and a run function that serves the inference_function, defining the model name, the inputs and the outputs along with optional configuration.Here is an example of a run.py file:
Dockerfile in your model directory.Dockerfile.Here is an example of a Dockerfile:
my_model directory.Replace my_model_image with the desired name for your docker image.
Tag and push the docker image to your container registry.
Create the function via the NVCF API. In this example, we defined the inference port as 8000 and are using the default inference and health endpoint paths.
See more examples of containers that are Cloud Functions compatible in the function samples directory.
Cloud Functions supports function invocation via gRPC. During function creation, specify that the function is a gRPC function by setting the inferenceUrl field to /grpc.
The function container must implement a gRPC port, endpoint and health check. The health check is expected to be served by the gRPC inference port, there is no need to define a separate health endpoint path.
When creating the gRPC function, set the inferenceUrl field to /grpc:
For gRPC authentication metadata, gateway address configuration, and client examples, see gRPC Function Invocation.