Models in Foundry can be directly published as a function provided they satisfy the requirements detailed below. This enables usage of models for live inference in Workshop, Vertex and other end-user facing applications. This can be done both from either a model with a direct deployment, or from a Modeling Objective with a live deployment. Both methods are functionally equivalent.
While these functions are simple wrappers around the model, more complex logic can be created by calling them in your code in a Functions repository.
To support direct publishing :
To publish a supported model as a Function with a direct model deployment, you must first create a direct model deployment. Once your direct model deployment is running, select the plus + icon in the sidebar and provide a model Function name. This Function will automatically upgrade with each new model version published to the model's branch.
To publish a supported model as a Function through a modeling objective, you must first create a live deployment. Once your model is running, navigate to the Details page of the deployment. From here, the Publish Function card will be visible.
Select the Publish Function button. You will then be guided through the process of setting parameters for the function.
Once your function has been published, the Publish Function card will display which function is backed by the live deployment. As with all functions, you can view your published function in the Ontology Manager, where health information about the deployment is also available.
It is important to be aware that an objective is limited to producing only one function. However, you can still publish new versions of that same function as needed.
When a model is retrained, or the deployment's API changes, you may need to publish a new function version. Below are example cases of when and how to publish a new function version as well as explanations of function publication behavior under different deployment modes.
Whenever a new version of the model is published on a branch with a function published, a new version of the associated function is also automatically created. However, as long as the API of the model does not change with the new version, consumers of the function will still work and will automatically use the new model version without requiring a logic update.
For example, assume you have a TypeScript function - the outer function — calling a model's published function. There is only one deployment on a branch at any given time, based on the latest model version; therefore, the model function on that branch can only point to that deployment. The model function itself is just a thin wrapper around this model deployment, and simply queries the model by URL (which is stable across model versions) and sends input data to the model. As long as the outer function sends data that matches the model's API and has correct logic to process the output data — in other words, as long as the model API has not changed — the model and function version change will not affect the outer function calling the model. This is true of TypeScript functions as well as other model function usage, such as direct Workshop or Vertex usage.
Once a new model version is published, all repositories importing the associated function will only allow importing the latest version. Any existing imports will seamlessly update to the latest version when the repository is opened, and check the model API against the data passed to it through via TypeScript type checking.
While only one function version can typically be imported in a given repository or application, users who want to import several model versions into their project for change management purposes can publish several functions on different branches to do so, since there can be one deployment and one function per branch on a model.
When a model is retrained without the model's API changing, there is no need to publish a new function version. The current version will still continue to point to the deployment. However, if you choose to publish a new function version, note that the old function version will continue to work.
If you attempt to release a model with a different model API to a live deployment, the following warning will appear:
Do not ignore this warning. Updating a live deployment to a new model with a different model API will require manual action to fix downstream usage. The dialog will guide you through the process of publishing new function versions for any deployment affected by the release.
Any usages of the current function version will break if you choose not to publish a new function version. To resolve this issue, return to the Details page of the deployment and publish a new function version from there.
For Models that are single tabular input to single tabular output, row-wise function publishing will be enabled by default. This allows the model API to be flattened for each inference call so that executing the function calls one tabular row as input and outputs one tabular row. Alternatively, consider using an Object or ObjectSet directly in the Model API to facilitate use of your Model with Objects in Functions.
For a model API that looks like the following:
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14
@classmethod def api(cls): inputs = { "input_df": pm.Pandas(columns=[("area_code", int), ("num_bedrooms", int), ("num_bathrooms", int)]) } outputs = { "output_df": pm.Pandas(columns=[("area_code", int), ("num_bedrooms", int), ("num_bathrooms", int), ("predicted_price", int)]) } return inputs, outputs
The direct publishing function signature with row wise would look like:
Copied!1 2 3 4 5 6 7 8 9 10
export async function housingPriceModelingObjective(parameters: { "area_code": FunctionsApi.Integer; "num_bedrooms": FunctionsApi.Integer; "num_bathrooms": FunctionsApi.Integer; }): Promise<{ "predicted_price": FunctionsApi.Double; "num_bathrooms": FunctionsApi.Integer; "area_code": FunctionsApi.Integer; "num_bedrooms": FunctionsApi.Integer; }>
The direct publishing function signature without row wise would look like:
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14
export async function housingPriceModelingObjective(parameters: { "input_df": Array<{ "num_bathrooms": FunctionsApi.Integer; "area_code": FunctionsApi.Integer; "num_bedrooms": FunctionsApi.Integer; }>; }): Promise<{ "output_df": Array<{ "predicted_price": FunctionsApi.Double; "num_bathrooms": FunctionsApi.Integer; "area_code": FunctionsApi.Integer; "num_bedrooms": FunctionsApi.Integer; }>; }>
To enable or disable row-wise processing for a given function, a new function version must be published and row-wise processing can be toggled under Advanced options.