|
14 | 14 | "id": "e9b8cb7c-1974-4af5-8992-d51f90fcfe5b", |
15 | 15 | "metadata": {}, |
16 | 16 | "source": [ |
17 | | - "# Automatic Generation of the requirements.json File\n", |
| 17 | + "# Automatic Generation of the requirements.json or requirements.txt File\n", |
18 | 18 | "In order to validate Python models within a container publishing destination, the Python packages which contain the modules that are used in the Python score code file and its score resource files must be installed in the run-time container. You can install the packages when you publish a Python model or decision that contains a Python model to a container publishing destination by adding a `requirements.json` file that includes the package install statements to your model.\n", |
19 | 19 | "\n", |
20 | 20 | "This notebook provides an example execution and assessment of the create_requirements_json() function added in python-sasctl v1.8.0. The aim of this function is help to create the instructions (aka the `requirements.json` file) for a lightweight Python container in SAS Model Manager. Lightweight here meaning that the container will only install the packages found in the model's pickle files and python scripts.\n", |
21 | 21 | "\n", |
| 22 | + "Additionally, the create_requirements_json() function provides an optional parameter `create_requirements_txt` which when set to `True` will generate a requirements.txt file alongside the requirements.json file. By default this option is set to `False`. The requirements.txt file is specifically needed when deploying Python models to SAS Event Stream Processing, which requires this format for package installation in their environment. While SAS Model Manager continues to use the requirements.json format, adding the requirements.txt file ensures compatibility across both platforms. \n", |
| 23 | + "\n", |
22 | 24 | "### **User Warnings**\n", |
23 | 25 | "The methods utilized in this function can determine package dependencies and versions from provided scripts and pickle files, but there are some stipulations that need to be considered:\n", |
24 | 26 | "\n", |
25 | 27 | "1. If run outside of the development environment that the model was created in, the create_requirements_json() function **CANNOT** determine the required package _versions_ accurately. \n", |
26 | | - "2. Not all Python packages have matching import and install names and as such some of the packages added to the requirements.json file may be incorrectly named (i.e. `import sklearn` vs `pip install scikit-learn`).\n", |
| 28 | + "2. Not all Python packages have matching import and install names and as such some of the packages added to the requirements.json file may be incorrectly named (i.e. `import sklearn` vs `pip install scikit-learn`). Some of the major packages with differing import and install names are automatically converted. \n", |
27 | 29 | "\n", |
28 | 30 | "As such, it is recommended that the user check over the requirements.json file for package name and version accuracy before deploying to a run-time container in SAS Model Manager." |
29 | 31 | ] |
|
63 | 65 | "outputs": [], |
64 | 66 | "source": [ |
65 | 67 | "model_dir = Path.cwd() / \"data/hmeqModels/DecisionTreeClassifier\"\n", |
66 | | - "requirements_json = pzmm.JSONFiles.create_requirements_json(model_dir)" |
| 68 | + "requirements_json = pzmm.JSONFiles.create_requirements_json(model_dir, create_requirements_txt=False)" |
67 | 69 | ] |
68 | 70 | }, |
69 | 71 | { |
|
145 | 147 | ], |
146 | 148 | "source": [ |
147 | 149 | "for requirement in requirements_json:\n", |
| 150 | + " # Example: Replace sklearn with scikit-learn in requirements\n", |
| 151 | + " # (This is redundant in newer versions but shows how to modify package names)\n", |
148 | 152 | " if 'sklearn' in requirement['step']:\n", |
149 | 153 | " requirement['command'] = requirement[\"command\"].replace('sklearn', 'scikit-learn')\n", |
150 | 154 | " requirement['step'] = requirement['step'].replace('sklearn', 'scikit-learn')\n", |
|
0 commit comments