Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
technical:recipes:keras-in-virtualenv [2021-02-24 23:44] – frey | technical:recipes:keras-in-virtualenv [2021-08-06 13:00] (current) – frey | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Keras Python Virtual Environment ====== | ||
+ | |||
+ | This page documents the creation of a Python virtual environment (virtualenv) containing the Keras deep-learning suite on the Caviness HPC system. | ||
+ | |||
+ | ===== Prepare Workgroup Directory ===== | ||
+ | |||
+ | Prepare to add software in the standard sub-directories of the workgroup storage: | ||
+ | |||
+ | <code bash> | ||
+ | [user@login01 ~]$ workgroup -g my_workgroup | ||
+ | [(my_workgroup: | ||
+ | [(my_workgroup: | ||
+ | </ | ||
+ | |||
+ | These commands create any missing directories. | ||
+ | |||
+ | ===== Create Keras Virtualenv ===== | ||
+ | |||
+ | All versions of the Keras virtualenv will be stored in the common base directory, '' | ||
+ | |||
+ | <code bash> | ||
+ | [(my_workgroup: | ||
+ | 20200204-sklearn | ||
+ | [(my_workgroup: | ||
+ | </ | ||
+ | |||
+ | The Intel Python distribution will form the basis for the Keras virtualenv, so add it to the environment: | ||
+ | |||
+ | <code bash> | ||
+ | [(my_workgroup: | ||
+ | Adding package `intel-python/ | ||
+ | (root) [(my_workgroup: | ||
+ | </ | ||
+ | |||
+ | Notice the prompt changed: | ||
+ | |||
+ | The Python environment will include Keras, numpy, and pip: | ||
+ | |||
+ | <code bash> | ||
+ | (root) [(my_workgroup: | ||
+ | </ | ||
+ | |||
+ | The conda environment builder will take some time to locate all the necessary packages and their dependencies. | ||
+ | |||
+ | <code bash> | ||
+ | Proceed ([y]/n)? y | ||
+ | </ | ||
+ | |||
+ | Answer " | ||
+ | |||
+ | <code bash> | ||
+ | (root) [(my_workgroup: | ||
+ | [(my_workgroup: | ||
+ | </ | ||
+ | |||
+ | Notice the '' | ||
+ | ===== VALET Package Definition ===== | ||
+ | |||
+ | Assuming the workgroup does //not// already have a Keras VALET package definition, the following text: | ||
+ | |||
+ | <file keras.vpkg_yaml> | ||
+ | keras: | ||
+ | prefix: / | ||
+ | description: | ||
+ | flags: | ||
+ | - no-standard-paths | ||
+ | actions: | ||
+ | - action: source | ||
+ | script: | ||
+ | sh: intel-python.sh | ||
+ | order: failure-first | ||
+ | success: 0 | ||
+ | versions: | ||
+ | " | ||
+ | description: | ||
+ | dependencies: | ||
+ | - intel-python/ | ||
+ | </ | ||
+ | |||
+ | would be added to '' | ||
+ | |||
+ | <file keras.vpkg_yaml> | ||
+ | keras: | ||
+ | prefix: / | ||
+ | description: | ||
+ | flags: | ||
+ | - no-standard-paths | ||
+ | actions: | ||
+ | - action: source | ||
+ | script: | ||
+ | sh: intel-python.sh | ||
+ | order: failure-first | ||
+ | success: 0 | ||
+ | versions: | ||
+ | " | ||
+ | description: | ||
+ | dependencies: | ||
+ | - intel-python/ | ||
+ | " | ||
+ | description: | ||
+ | dependencies: | ||
+ | - intel-python/ | ||
+ | " | ||
+ | description: | ||
+ | dependencies: | ||
+ | - intel-python/ | ||
+ | </ | ||
+ | |||
+ | <note tip>On Caviness after a user has used the '' | ||
+ | |||
+ | ===== Install SKLearn ===== | ||
+ | |||
+ | The SKLearn package is not present in the conda online repositories, | ||
+ | |||
+ | <code bash> | ||
+ | [(my_workgroup: | ||
+ | Adding dependency `intel-python/ | ||
+ | Adding package `keras/ | ||
+ | (/ | ||
+ | / | ||
+ | </ | ||
+ | |||
+ | A prefix has reappeared on the prompt — the path at which the new Keras virtualenv was created — and the '' | ||
+ | |||
+ | <code bash> | ||
+ | (/ | ||
+ | Collecting sklearn | ||
+ | Downloading .. | ||
+ | : | ||
+ | Successfully built sklearn | ||
+ | Installing collected packages: joblib, scikit-learn, | ||
+ | Successfully installed joblib-0.14.1 scikit-learn-0.22.1 sklearn-0.0 | ||
+ | (/ | ||
+ | 0.22.1 | ||
+ | </ | ||
+ | |||
+ | The Keras environment with SKLearn is now ready for use. | ||
+ | |||
+ | ===== Job Scripts ===== | ||
+ | |||
+ | Any job scripts you submit that want to run scripts using this virtualenv should include something like the following toward its end: | ||
+ | |||
+ | < | ||
+ | # | ||
+ | # Setup Keras virtualenv: | ||
+ | # | ||
+ | vpkg_require keras/ | ||
+ | |||
+ | # | ||
+ | # Run a Python script in that virtualenv: | ||
+ | # | ||
+ | python3 my_keras_work.py | ||
+ | rc=$? | ||
+ | |||
+ | # | ||
+ | # Do cleanup work, etc.... | ||
+ | # | ||
+ | |||
+ | # | ||
+ | # Exit with whatever exit code our Python script handed back: | ||
+ | # | ||
+ | exit $rc | ||
+ | </ | ||