This article explains how to create Python Code Objects using the Rhino FCP UI. Python code objects allow you to provide your code to FCP without having to containerize it.
Note: To learn how to create a Python Code Object using the Rhino SDK, see Creating a Python Code Object Using the Rhino SDK.
Creating a Python Code Object
To create a new code object, follow these steps.
- Go to the main project's page and select your project.
- Select Code from the menu on the left to open the Code Objects page. To search for code objects, use the text boxes located at the top right corner of the page. To search by name enter the full name or part of the name in the Search Name text box. To search by description, enter part of the description in the Search Description text box.
- Select the Create New Code Object button to open the Create New Code Object page. You might need to scroll down to see the entire page.
- Enter the following:
- Ensure that Python Code is selected as the Code Object Type.
- Enter Details about this code object, including the name you would like to provide for your code object and optionally, a description. The description that will help you and others understand the nature of this Code Object.
- Add the inputs, which are what the Data Schema(s) for the Datasets this Code Object will accept as input. Your selection here will affect which Datasets can be selected as input when triggering a Code Run with this Code Object.
- Enter the outputs for the Data Schema(s) for the Datasets that will be created as output when triggering a Code Run with this Code Object. You can also select the option to [Auto-generate Data Schema from Data]. For more information about Auto-generating Data Schemas, please refer to Auto-Generated Data Schemas.
- Enter the container details. This is where you can specify parameters that will define your Code Object container:
- Python and CUDA Versions, or conversely
- Pre-existing Container Base Image (from Dockerhub). By default, the FCP will use the
python:3.9.7-slim-bullseyedocker image. This means your code will run within a Python 3.9 environment. You are free to select whichever docker base image makes the most sense for your use case (i.e. an image that supports GPU operations).
- Your code can be provided as a code snippet, standalone file, or an upload file. The information about each appears below.
-
Code Snippet - Ideal for relatively straightforward scripts that primarily utilize basic Python packages, along with Pandas and Numpy. FCP automatically provides access to your cohort data as a Pandas Dataframe named df. Additionally, it generates the output cohort of your model from this same Dataframe. This setup facilitates elementary Pandas-based operations on your raw input data, such as feature extraction and value normalization.
As an example, consider this Python code snippet:
normalized_df = (df-df.mean())/df.std() df = normalized_df
Executing this code snippet yields an output cohort with z-normalized numerical features, all without requiring any additional code.
- Standalone File - This option grants you the freedom to execute varied Python code with custom dependencies, extending beyond Pandas and Numpy. The Standalone File option lets you specify your code's prerequisites, which will be automatically installed within the image generated by FCP. If your code necessitates a specific environment – for instance, to support GPU operations - you can define the Container Base Image that supports it. Use this option for more complex code, which can still be run as a single file. Unlike the Code Snippet, no additional "hidden" functionality is included here.
- Upload File(s) - This option is similar to "Standalone File", but allows you to provide your code in more than one file, e.g., multiple Python files and/or shell scripts. Files can include non-Python files of any format, such as configuration files, model parameter files, and so forth. You just have to upload the files you need, or a folder(s), and select the entry point in the text box that appears when this option is selected. The entry point is the file that you'd like your container to run. Be sure to specify code requirements and the container environment as needed.
NOTE: To see how you adapt your code to access your data, see Accessing your datasets in Code Objects
- Enter the requirements. This field enables you to specify Python libraries that are required to run your code. This capability is enabled for all Python Code types except for Code Snippet which has two locked dependencies—Pandas and NumPy. Paste all Python dependencies that are necessary for running your previously specified Python code. These dependencies will automatically be installed by the Rhino FCP when it builds your container in the background. Alternatively, click Upload File to load a requirements file from your local computer. The Rhino FCP supports both Pip and Conda as package management frameworks.
- If you will be running your code object on the Google Cloud Platform (GCP) and you want to set minimum CPU, RAM, VRAM, and GPU resources, complete the steps in the Setting Required Compute Resources (Autoscaling) section of this document. If not, go to the next step.
- When complete, click Create New Code Object or start a Code Run.
Setting Required Compute Resources (Autoscaling)
NOTE: This feature is only available if you are running on the Google Cloud Platform (GCP). For NVFlare code objects and code runs, you can adjust autoscaling methods for both the NVFlare Server and the NVFlare Client. For the NVFlare Server, you can only specify the CPU and RAM.
Autoscaling allows Rhino to run Code Runs on additional compute resources when the default Rhino Client capacity is not sufficient. This capability is designed to support resource‑intensive, "bursty"(processing tasks occur in short, intense or irregular spurts), or GPU‑based workloads while improving isolation, reliability, and cost efficiency. With autoscaling enabled, Rhino provisions temporary cloud VMs on demand, executes workloads on those VMs, and automatically terminates them when execution completes.
To help you make more efficient use of your computing resources and save on costs, you can indicate the minimum number of CPUs, amount of RAM, the disk size (VRAM), as well as the type and number of GPUs. You can adjust these settings when you create a code object and also when you run your code. Note that adjustments do not persist and will need to be reset with each run.
To set the required compute resources, complete the following steps.
-
In the Required Compute Resources section, move the
No minimum, allow any compute requirements slider to the right.
The compute resources that can be changed become visible.
- Next, make changes to the settings as needed. Note that these settings changes do not persist the next time you run the code object or the code run. The settings are explained below.
| Setting | Description | Usage Notes |
| CPU MIN | The minimum number of CPU cores on which your code will be run. | If the CPU MIN is too low, you might see slow code execution or throttling. |
| RAM MIN | The minimum amount of RAM (main memory) that you want to allocate to running your code. | If this is too low, you might see an out-of-memory crash or slowness in execution due to disk swapping. |
| DISK SIZE | Amount of storage allocated to the instance. | Increasing this setting increases capacity (not necessarily speed) |
| GPU TYPE | The model of GPU hardware. The number of GPUs indicate the number of GPUs attached to the instance. | If your code isn’t written to use multiple GPUs, extra GPUs might not be used. Note that GPU availability depends on the selected cloud region, Project‑level GPU quotas, and the current capacity at the cloud provider. |
- Select Run without GPU if no GPU instance is available if your code supports CPU fallback, or if your GPU capacity is limited, but you are fine with slower results. This option can be good if you are debugging or testing, running small datasets, or running inference for small batches.
- Select Always create a new virtual machine allows GCP. By default a new virtual machine is always created at runtime.
- When complete, click Create New Code Object or start a Code Run.
Creating a New Version of a Python Code Object
To create a new version, complete the following steps.
- Go to the page that has the original object you want to create a new version of.
- In the upper right corner of the box where your original object is, select the + New Version button.
- A new window appears that allows you to create a new version of your object.
Getting Help
If you have received an error or run into any issues throughout the process, please reach out to support@rhinohealth.com for more assistance.