|
| 1 | +# Recommender Operator |
| 2 | + |
| 3 | +Recommender Systems are designed to suggest relevant items, products, or content to users based on their preferences and behaviors. These systems are widely used in various industries such as e-commerce, entertainment, and social media to enhance user experience by providing personalized recommendations. They help in increasing user engagement, satisfaction, and sales by predicting what users might like or need based on their past interactions and the preferences of similar users. |
| 4 | + |
| 5 | + |
| 6 | +Below are the steps to configure and run the Recommender Operator on different resources. |
| 7 | + |
| 8 | +## 1. Prerequisites |
| 9 | + |
| 10 | +Follow the [CLI Configuration](https://accelerated-data-science.readthedocs.io/en/latest/user_guide/cli/opctl/configure.html) steps from the ADS documentation. This step is mandatory as it sets up default values for different options while running the Recommender Operator on OCI Data Science jobs or OCI Data Flow applications. If you have previously done this and used a flexible shape, make sure to adjust `ml_job_config.ini` with shape config details and `docker_registry` information. |
| 11 | + |
| 12 | +- ocpus = 1 |
| 13 | +- memory_in_gbs = 16 |
| 14 | +- docker_registry = `<iad.ocir.io/namespace/>` |
| 15 | + |
| 16 | +## 2. Generating configs |
| 17 | + |
| 18 | +To generate starter configs, run the command below. This will create a list of YAML configs and place them in the `output` folder. |
| 19 | + |
| 20 | +```bash |
| 21 | +ads operator init -t recommender --overwrite --output ~/recommender/ |
| 22 | +``` |
| 23 | + |
| 24 | +The most important files expected to be generated are: |
| 25 | + |
| 26 | +- `recommender.yaml`: Contains recommender related configuration. |
| 27 | +- `backend_operator_local_python_config.yaml`: This includes a local backend configuration for running recommender in a local environment. The environment should be set up manually before running the operator. |
| 28 | +- `backend_operator_local_container_config.yaml`: This includes a local backend configuration for running recommender within a local container. The container should be built before running the operator. Please refer to the instructions below for details on how to accomplish this. |
| 29 | +- `backend_job_container_config.yaml`: Contains Data Science job-related config to run recommender in a Data Science job within a container (BYOC) runtime. The container should be built and published before running the operator. Please refer to the instructions below for details on how to accomplish this. |
| 30 | +- `backend_job_python_config.yaml`: Contains Data Science job-related config to run recommender in a Data Science job within a conda runtime. The conda should be built and published before running the operator. |
| 31 | + |
| 32 | +All generated configurations should be ready to use without the need for any additional adjustments. However, they are provided as starter kit configurations that can be customized as needed. |
| 33 | + |
| 34 | +## 3. Running recommender on the local conda environment |
| 35 | + |
| 36 | +To run recommender locally, create and activate a new conda environment (`ads-recommender`). Install all the required libraries listed in the `environment.yaml` file. |
| 37 | + |
| 38 | +```yaml |
| 39 | +- report-creator |
| 40 | +- cerberus |
| 41 | +- "git+https://github.com/oracle/accelerated-data-science.git@feature/recommender#egg=oracle-ads" |
| 42 | +``` |
| 43 | +
|
| 44 | +Please review the previously generated `recommender.yaml` file using the `init` command, and make any necessary adjustments to the input and output file locations. By default, it assumes that the files should be located in the same folder from which the `init` command was executed. |
| 45 | + |
| 46 | +Use the command below to verify the recommender config. |
| 47 | + |
| 48 | +```bash |
| 49 | +ads operator verify -f ~/recommender/recommender.yaml |
| 50 | +``` |
| 51 | + |
| 52 | +Use the following command to run the recommender within the `ads-recommender` conda environment. |
| 53 | + |
| 54 | +```bash |
| 55 | +ads operator run -f ~/recommender/recommender.yaml -b local |
| 56 | +``` |
| 57 | + |
| 58 | +The operator will run in your local environment without requiring any additional modifications. |
| 59 | + |
| 60 | +## 4. Running recommender on the local container |
| 61 | + |
| 62 | +To run the recommender operator within a local container, follow these steps: |
| 63 | + |
| 64 | +Use the command below to build the recommender container. |
| 65 | + |
| 66 | +```bash |
| 67 | +ads operator build-image -t recommender |
| 68 | +``` |
| 69 | + |
| 70 | +This will create a new `recommender:v1` image, with `/etc/operator` as the designated working directory within the container. |
| 71 | + |
| 72 | + |
| 73 | +Check the `backend_operator_local_container_config.yaml` config file. By default, it should have a `volume` section with the `.oci` configs folder mounted. |
| 74 | + |
| 75 | +```yaml |
| 76 | +volume: |
| 77 | + - "/Users/<user>/.oci:/root/.oci" |
| 78 | +``` |
| 79 | + |
| 80 | +Mounting the OCI configs folder is only required if an OCI Object Storage bucket will be used to store the input recommender data or output recommender result. The input/output folders can also be mounted to the container. |
| 81 | + |
| 82 | +```yaml |
| 83 | +volume: |
| 84 | + - /Users/<user>/.oci:/root/.oci |
| 85 | + - /Users/<user>/recommender/data:/etc/operator/data |
| 86 | + - /Users/<user>/recommender/result:/etc/operator/result |
| 87 | +``` |
| 88 | + |
| 89 | +The full config can look like: |
| 90 | +```yaml |
| 91 | +kind: operator.local |
| 92 | +spec: |
| 93 | + image: recommender:v1 |
| 94 | + volume: |
| 95 | + - /Users/<user>/.oci:/root/.oci |
| 96 | + - /Users/<user>/recommender/data:/etc/operator/data |
| 97 | + - /Users/<user>/recommender/result:/etc/operator/result |
| 98 | +type: container |
| 99 | +version: v1 |
| 100 | +``` |
| 101 | + |
| 102 | +Run the recommender within a container using the command below: |
| 103 | + |
| 104 | +```bash |
| 105 | +ads operator run -f ~/recommender/recommender.yaml --backend-config ~/recommender/backend_operator_local_container_config.yaml |
| 106 | +``` |
| 107 | + |
| 108 | +## 5. Running recommender in the Data Science job within container runtime |
| 109 | + |
| 110 | +To execute the recommender operator within a Data Science job using container runtime, please follow the steps outlined below: |
| 111 | + |
| 112 | +You can use the following command to build the recommender container. This step can be skipped if you have already done this for running the operator within a local container. |
| 113 | + |
| 114 | +```bash |
| 115 | +ads operator build-image -t recommender |
| 116 | +``` |
| 117 | + |
| 118 | +This will create a new `recommender:v1` image, with `/etc/operator` as the designated working directory within the container. |
| 119 | + |
| 120 | +Publish the `recommender:v1` container to the [Oracle Container Registry](https://docs.public.oneportal.content.oci.oraclecloud.com/en-us/iaas/Content/Registry/home.htm). To become familiar with OCI, read the documentation links posted below. |
| 121 | + |
| 122 | +- [Access Container Registry](https://docs.public.oneportal.content.oci.oraclecloud.com/en-us/iaas/Content/Registry/Concepts/registryoverview.htm#access) |
| 123 | +- [Create repositories](https://docs.public.oneportal.content.oci.oraclecloud.com/en-us/iaas/Content/Registry/Tasks/registrycreatingarepository.htm#top) |
| 124 | +- [Push images](https://docs.public.oneportal.content.oci.oraclecloud.com/en-us/iaas/Content/Registry/Tasks/registrypushingimagesusingthedockercli.htm#Pushing_Images_Using_the_Docker_CLI) |
| 125 | + |
| 126 | +To publish `recommender:v1` to OCR, use the command posted below: |
| 127 | + |
| 128 | +```bash |
| 129 | +ads operator publish-image recommender:v1 --registry <iad.ocir.io/tenancy/> |
| 130 | +``` |
| 131 | + |
| 132 | +After the container is published to OCR, it can be used within Data Science jobs service. Check the `backend_job_container_config.yaml` config file. It should contain pre-populated infrastructure and runtime sections. The runtime section should contain an image property, something like `image: iad.ocir.io/<tenancy>/recommender:v1`. More details about supported options can be found in the ADS Jobs documentation - [Run a Container](https://accelerated-data-science.readthedocs.io/en/latest/user_guide/jobs/run_container.html). |
| 133 | + |
| 134 | +Adjust the `recommender.yaml` config with proper input/output folders. When the recommender is run in the Data Science job, it will not have access to local folders. Therefore, input data and output folders should be placed in the Object Storage bucket. Open the `recommender.yaml` and adjust the following fields: |
| 135 | + |
| 136 | +```yaml |
| 137 | +input_data: |
| 138 | + url: oci://bucket@namespace/recommender/input_data/data.csv |
| 139 | +output_directory: |
| 140 | + url: oci://bucket@namespace/recommender/result/ |
| 141 | +``` |
| 142 | + |
| 143 | +Run the recommender on the Data Science jobs using the command posted below: |
| 144 | + |
| 145 | +```bash |
| 146 | +ads operator run -f ~/recommender/recommender.yaml --backend-config ~/recommender/backend_job_container_config.yaml |
| 147 | +``` |
| 148 | + |
| 149 | +The logs can be monitored using the `ads opctl watch` command. |
| 150 | + |
| 151 | +```bash |
| 152 | +ads opctl watch <OCID> |
| 153 | +``` |
| 154 | + |
| 155 | +## 6. Running recommender in the Data Science job within conda runtime |
| 156 | + |
| 157 | +To execute the recommender operator within a Data Science job using conda runtime, please follow the steps outlined below: |
| 158 | + |
| 159 | +You can use the following command to build the recommender conda environment. |
| 160 | + |
| 161 | +```bash |
| 162 | +ads operator build-conda -t recommender |
| 163 | +``` |
| 164 | + |
| 165 | +This will create a new `recommender_v1` conda environment and place it in the folder specified within `ads opctl configure` command. |
| 166 | + |
| 167 | +Use the command below to Publish the `recommender_v1` conda environment to the Object Storage bucket. |
| 168 | + |
| 169 | +```bash |
| 170 | +ads operator publish-conda -t recommender |
| 171 | +``` |
| 172 | +More details about configuring CLI can be found here - [Configuring CLI](https://accelerated-data-science.readthedocs.io/en/latest/user_guide/cli/opctl/configure.html) |
| 173 | + |
| 174 | + |
| 175 | +After the conda environment is published to Object Storage, it can be used within Data Science jobs service. Check the `backend_job_python_config.yaml` config file. It should contain pre-populated infrastructure and runtime sections. The runtime section should contain a `conda` section. |
| 176 | + |
| 177 | +```yaml |
| 178 | +conda: |
| 179 | + type: published |
| 180 | + uri: oci://bucket@namespace/conda_environments/cpu/recommender/1/recommender_v1 |
| 181 | +``` |
| 182 | + |
| 183 | +More details about supported options can be found in the ADS Jobs documentation - [Run a Python Workload](https://accelerated-data-science.readthedocs.io/en/latest/user_guide/jobs/run_python.html). |
| 184 | + |
| 185 | +Adjust the `recommender.yaml` config with proper input/output folders. When the recommender is run in the Data Science job, it will not have access to local folders. Therefore, input data and output folders should be placed in the Object Storage bucket. Open the `recommender.yaml` and adjust the following fields: |
| 186 | + |
| 187 | +```yaml |
| 188 | +input_data: |
| 189 | + url: oci://bucket@namespace/recommender/input_data/data.csv |
| 190 | +output_directory: |
| 191 | + url: oci://bucket@namespace/recommender/result/ |
| 192 | +test_data: |
| 193 | + url: oci://bucket@namespace/recommender/input_data/test.csv |
| 194 | +``` |
| 195 | + |
| 196 | +Run the recommender on the Data Science jobs using the command posted below: |
| 197 | + |
| 198 | +```bash |
| 199 | +ads operator run -f ~/recommender/recommender.yaml --backend-config ~/recommender/backend_job_python_config.yaml |
| 200 | +``` |
| 201 | + |
| 202 | +The logs can be monitored using the `ads opctl watch` command. |
| 203 | + |
| 204 | +```bash |
| 205 | +ads opctl watch <OCID> |
| 206 | +``` |
0 commit comments