Skip to main content
Version: 0.9

Custom Environments for On-Demand Feature Views

Private Preview

This feature is currently in Private Preview.

This feature has the following limitations:
  • This feature is only available in Tecton SDK version >= 0.8
If you would like to participate in the preview, please file a feature request.

Tecton allows users to create custom Python Environments for On-Demand Feature Views. These environments can be created using a python requirements file that includes all the dependencies required in the custom environment.

Creating Custom Environments

The process for creating custom environments is as follows:

  1. Create requirements file
  2. Create a custom environment via the Tecton CLI
  3. Use your custom environment in ODFVs

Create a requirements file

Create a requirements.txt file that lists all the packages that your project requires.

Here's a sample template for a requirements.txt file:

# PyPI packages
fuzzywuzzy==0.18.0
tecton-runtime==0.0.2

# Packages from GitHub repositories
git+https://@github.com/<owner>/<repository>.git@<commit-ish>#egg=<package-name>

# Local wheel files
./wheels/my_local_package.whl
../other_project/wheels/another_local_package.whl

# Wheel files from S3
https://s3.amazonaws.com/my-bucket/wheels/s3_package_1.whl
https://s3.amazonaws.com/my-bucket/wheels/s3_package_2.whl

Below is a sample requirements.txt that will be used in this tutorial:

pytz==2023.3.post1
pycountry==18.12
fuzzywuzzy==0.18.0
tecton-runtime==0.0.2
  • The requirements.txt must include the tecton-runtime package. We recommend using the most recent version of this package.
  • Users can optionally run the resolve-dependencies CLI command to test and verify that the dependency set can be successfully resolved by Tecton and also view the fully resolved set of requirements.

Create an environment via the Tecton CLI

To create an environment in Tecton, you can use the tecton environment create command.

tecton environment create --name "my-custom-env" --description "This is a custom environment" --requirements /path/to/requirements.txt
tecton environment get --name "my-custom-env"

Id Name Status Created At
========================================================================================================================
5c83b9014e2e4f1eb68c58eba6bc0796 my-custom-env REMOTE_ENVIRONMENT_STATUS_PENDING 2023-08-29 20:18:55 UTC
  • You will require admin privileges to create and delete custom environments via the Tecton CLI.
  • Custom environments need unique names across all workspaces and can only contain letters, numbers, hyphens, or underscores.
  • Each dependency listed in the requirements.txt must have a .whl(wheel) file available for download in PyPI or any custom artifactory provided for the relevant Python version and x86 architecture.
  • By default, the requirements are resolved for Python version 3.8 and x86 architecture. To create an environment with Python 3.9, use the --python-version option for the create command. See Command Options for more information.
  • Environment creation takes place asynchronously, and so you will need to wait for the environment to be REMOTE_ENVIRONMENT_STATUS_READY before using it. You can check the status of the environment using the tecton environment get command. The environment creation typically takes 2-5 minutes.
  • You can use the tecton environment describe command to see the input requirements as well as the fully resolved set of dependencies for an environment.

Use Environment in ODFVs

You can now specify the environment in your Feature definitions.

Below is an example On Demand Feature View that uses the fuzzywuzzy package available in the my-custom-env environment

from tecton import on_demand_feature_view, RequestSource
from tecton.types import Field, Int64, String

request_schema = [Field("text", String)]
similarity_request = RequestSource(schema=request_schema)
output_schema = [Field("similarity", Int64), Field("partial_similarity", Int64)]


@on_demand_feature_view(
sources=[similarity_request],
mode="python",
schema=output_schema,
environments=["my-custom-env"],
)
def fuzzy_similarity(request):
from fuzzywuzzy import fuzz

baseline = "Mocha Cheesecake Fudge Brownie Bars"
result = {
"similarity": fuzz.ratio(baseline, request["text"]),
"partial_similarity": fuzz.partial_ratio(baseline, request["text"]),
}
return result

Note that:

  • If environments is not specified for an On-Demand Feature View, then it is assumed to be compatible with all environments.
  • If the dependency required for your Feature View is available in multiple environments, then you can include the set of environments in this list.

You can now set the execution environment for a Feature Service containing the above ODFV as follows:

from tecton import FeatureService
from ads.features.on_demand_feature_views.similarity import fuzzy_similarity

similarity_feature_service = FeatureService(
name="similarity_feature_service",
on_demand_environment="my-custom-env",
online_serving_enabled=True,
features=[fuzzy_similarity],
)
  • Note that a Feature View can support multiple environments. The specific execution environment will be configured in the Feature Service definition using the on_demand_environment parameter.
  • During execution, all On-Demand Feature Views within a Feature Service run in the same Environment. As a result, the on_demand_environment specified in the Feature Service must be on the environments list for all On-Demand Feature Views included in the features list.
  • Conversely, if an On-Demand Feature View specifies an environments constraint, then any Feature Service that includes the On-Demand Feature View must specify an on_demand_environment on that list.
  • Custom environments created via the CLI can be used in any workspace.

Delete an Environment

A custom environment can be deleted via the CLI using the tecton environment delete command. Please note that environment deletion will fail if the environment is actively being used in any Feature Service(s).

FAQs

  • Can an On Demand Feature View run in multiple environments?
    • Yes, an On Demand Feature View can run in multiple environments. The specific execution environment that an On Demand Feature View will run in is configured in the Feature Service containing it using the on_demand_environment parameter.
  • Can I use custom wheels in my environment?
    • Yes, you can include custom wheels in the requirements.txt file. Any custom packages will be installed in the /var/task path in the execution environment.
  • Why do I see timeouts when querying my newly created Feature Service using an environment?
    • Timeouts are expected when querying a newly created Feature Service using an environment, as the environment is still being warmed up by Tecton.
  • I'm running into dependency resolution errors while creating an environment with my requirements.txt. How do I resolve them?
    • Dependency resolution errors can be caused by conflicting version requirements in the requirements.txt file. Run the resolve-dependencies CLI command to test dependency resolution and identify the incompatible version specifications.
    • Verify that each dependency in the requirements.txt file has a wheel file available for download in PyPI (or any custom artifactory used) for x86 architecture and specific Python version used.
    • Tecton uses the pex utility to generate the fully resolved dependency set. For inspecting the underlying commands, run the resolve-dependencies CLI command with --verbose flag set.
  • How do I check the dependencies available in my custom environment?
    • You can use the tecton environment describe command to see the input requirements as well as the fully resolved set of dependencies for a custom environment.

Was this page helpful?

🧠 Hi! Ask me anything about Tecton!

Floating button icon