technical:recipes:tensorflow-in-virtualenv

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
technical:recipes:tensorflow-in-virtualenv [2025-10-24 16:26] – [Create TensorFlow Virtualenv] thuachentechnical:recipes:tensorflow-in-virtualenv [2025-11-06 15:30] (current) – [Create TensorFlow Virtualenv] thuachen
Line 14: Line 14:
 </code> </code>
  
-These commands create any missing directories.  All directories created will have group-write and -inherit permissions.+These commands create any missing directories.  All directories created will have group-write and inherit permissions.
  
 ===== Create TensorFlow Virtualenv ===== ===== Create TensorFlow Virtualenv =====
-We will need to load Minicoda and create the virtual environment:+First, we will need to load the Miniconda VALET package and create the virtual environment:
  
 <code bash> <code bash>
-[(my_workgroup:user)@login01 ~]$ vpkg_require miniconda/25.1.1.2+[(my_workgroup:user)@login01 ~]$ vpkg_devrequire miniconda/25.1.1.2
 Adding package `miniconda/25.1.1.2` to your environment Adding package `miniconda/25.1.1.2` to your environment
 </code> </code>
  
-The ''conda search tensorflow'' command can be used to locate the specific version you wish to install.  Two examples are shown:  TensorFlow release at least 2.19.0 with CUDA support; and version of TensorFlow 2.19.0 in the conda-forge channel.+The ''conda search tensorflow'' command can be used to locate the specific version you wish to install.  The example shows a search for TensorFlow CPU release at least 2.17.0.
  
 <code bash> <code bash>
-[(my_workgroup:user)@login01 ~]$ conda search 'tensorflow>=2.19.0=cuda*'+[(my_workgroup:user)@login01 ~]$ conda search 'tensorflow>=2.17.0'
 Loading channels: done Loading channels: done
 # Name                       Version           Build  Channel # Name                       Version           Build  Channel
-tensorflow                    2.19.0 cuda128py310h40b8f1e_202  conda-forge +tensorflow                    2.17.0 cpu_py310h42475c5_0  conda-forge 
-tensorflow                    2.19.0 cuda128py311h995fa60_202  conda-forge +tensorflow                    2.17.0 cpu_py310h42475c5_1  conda-forge 
-tensorflow                    2.19.0 cuda128py312hae5ec6b_202  conda-forge+tensorflow                    2.17.0 cpu_py310h42475c5_2  conda-forge
  
-[(my_workgroup:user)@login01 ~]$ conda search 'tensorflow[version=2.19.0,channel=conda-forge]' +... 
-Loading channels: done + 
-# Name                       Version           Build  Channel +tensorflow                    2.19.0 cpu_py312h69ecde4_3  conda-forge
-tensorflow                    2.19.0 cpu_py310h42475c5_2  conda-forge +
-tensorflow                    2.19.0 cpu_py310h42475c5_52  conda-forge +
-tensorflow                    2.19.0 cpu_py311h6ac8430_2  conda-forge +
-tensorflow                    2.19.0 cpu_py311h6ac8430_52  conda-forge +
-tensorflow                    2.19.0 cpu_py312h69ecde4_2  conda-forge+
 tensorflow                    2.19.0 cpu_py312h69ecde4_52  conda-forge tensorflow                    2.19.0 cpu_py312h69ecde4_52  conda-forge
-tensorflow                    2.19.0 cuda128py310h40b8f1e_202  conda-forge +tensorflow                    2.19.0 cpu_py312h69ecde4_53  conda-forge
-tensorflow                    2.19.0 cuda128py311h995fa60_202  conda-forge +
-tensorflow                    2.19.0 cuda128py312hae5ec6b_202  conda-forge+
 </code> </code>
- +All versions of the TensorFlow virtual environment will be stored in the directory ''$WORKDIR/sw/tensorflow''; each virtual environment must have a unique name that will become the VALET version of TensorFlow. In this tutorial, we will install the Tensorflow version 2.17.0 with the CPU support and with CUDA support. An appropriate version for the former would be ''2.17.0:cpu'' and the latter ''2.17.0:cuda'' Those versions can be translated to VALET-friendly directory names:
-All versions of the TensorFlow virtual environment will be stored in the directory ''$WORKDIR/sw/tensorflow''; each virtual environment must have a unique name that will become the VALET version of TensorFlow. In this tutorial, we will install the Tensorflow version 2.19.0 with and without the CUDA support. An appropriate version for the former would be ''2.19.0:cpu'' and the latter ''2.19.0:cuda'' Those versions can be translated to VALET-friendly directory names:+
  
 <code bash> <code bash>
-[(my_workgroup:user)@login01 ~]$ vpkg_id2path --version-id=2.19.0:cpu +[(my_workgroup:user)@login01 ~]$ vpkg_id2path --version-id=2.17.0:cpu 
-2.2.0-gpu +2.17.0-cpu 
-[(my_workgroup:user)@login01 ~]$ mkdir --mode=3750 ${WORKDIR}/sw/tensorflow/2.19.0-cpu+[(my_workgroup:user)@login01 ~]$ mkdir --mode=3750 ${WORKDIR}/sw/tensorflow/2.17.0-cpu
  
-[(my_workgroup:user)@login01 ~]$ vpkg_id2path --version-id=2.19.0:cuda +[(my_workgroup:user)@login01 ~]$ vpkg_id2path --version-id=2.17.0:cuda 
-2.3.0-intel-python3.8 +2.17.0-cuda 
-[(my_workgroup:user)@login01 ~]$ mkdir --mode=3750 ${WORKDIR}/sw/tensorflow/2.19.0-cuda+[(my_workgroup:user)@login01 ~]$ mkdir --mode=3750 ${WORKDIR}/sw/tensorflow/2.17.0-cuda
 </code> </code>
  
Line 63: Line 55:
  
 <code bash> <code bash>
-[(my_workgroup:user)@login01 ~]$ conda create --prefix=${WORKDIR}/sw/tensorflow/2.19.0-cpu 'tensorflow[version=2.19.0,build=cpu_py312h69ecde4_52]' +[(my_workgroup:user)@login01 ~]$ conda create --prefix=${WORKDIR}/sw/tensorflow/2.17.0-cpu 'tensorflow[version=2.17.0,build=cpu_py310h42475c5_0]' 
-WARNING: A directory already exists at the target location '/work/workgroup/sw/tensorflow/2.19.0-cpu'+WARNING: A directory already exists at the target location '/work/workgroup/sw/tensorflow/2.17.0-cpu'
 but it is not a conda environment. but it is not a conda environment.
 Continue creating environment (y/[n])? y Continue creating environment (y/[n])? y
Line 76: Line 68:
 # To activate this environment, use # To activate this environment, use
 # #
-#     $ conda activate /work/workgroup/sw/tensorflow/2.19.0-cpu+#     $ conda activate /work/workgroup/sw/tensorflow/2.17.0-cpu
 # #
 # To deactivate an active environment, use # To deactivate an active environment, use
Line 86: Line 78:
  
 <code bash> <code bash>
-[(my_workgroup:user)@login01 ~]$ conda create --prefix=${WORKDIR}/sw/tensorflow/2.19.0-cuda 'tensorflow[version=2.19.0,build=cuda128py312hae5ec6b_202,channel=conda-forge]' +[(my_workgroup:user)@login01 ~]$ conda create --prefix=${WORKDIR}/sw/tensorflow/2.17.0-cuda 'python==3.10' -c conda-forge 
-WARNING: A directory already exists at the target location '/work/workgroup/sw/tensorflow/2.19.0-cuda'+WARNING: A directory already exists at the target location '/work/workgroup/sw/tensorflow/2.17.0-cuda'
 but it is not a conda environment. but it is not a conda environment.
 Continue creating environment (y/[n])? y Continue creating environment (y/[n])? y
Line 99: Line 91:
 # To activate this environment, use # To activate this environment, use
 # #
-#     $ conda activate /work/workgroup/sw/tensorflow/2.3.0-intel-python3.8+#     $ conda activate /work/workgroup/sw/tensorflow/2.17.0-cuda
 # #
 # To deactivate an active environment, use # To deactivate an active environment, use
Line 105: Line 97:
 #     $ conda deactivate #     $ conda deactivate
 </code> </code>
- +We will need to run the ''conda activate'' command and then install the Tensorflow with cuda: 
-Ignore that ''conda activate'' command as well. Roll back the environment changes before proceeding:+<code bash> 
 +[(my_workgroup:user)@login01 ~]$ conda activate /work/workgroup/sw/tensorflow/2.17.0-cuda 
 +(/work/workgroup/sw/tensorflow/2.17.0-cuda)[(my_workgroup:user)@login01 ~]$ pip install "tensorflow[and-cuda]==2.17.0" 
 +</code> 
 +Use ''conda deactivate'' command to exit the virtual environment. Roll back the environment changes before proceeding:
  
 <code bash> <code bash>
-[(my_workgroup:user)@login01 ~]$ vpkg_rollback +(/work/workgroup/sw/tensorflow/2.17.0-cuda)[(my_workgroup:user)@login01 ~]$ conda deactivate 
-[(my_workgroup:user)@login01 ~]$ +[(my_workgroup:user)@login01 ~]$ vpkg_rollback all
 </code> </code>
  
Line 127: Line 123:
         - action: source         - action: source
           script:           script:
-              sh: anaconda-activate.sh+              sh: miniconda-activate.sh
           order: failure-first           order: failure-first
           success: 0           success: 0
     versions:     versions:
-        "2.2.0:gpu": +        "2.17.0:cpu": 
-            description: 2.2.0 with GPU support+            description: 2.17.0 with CPU support
             dependencies:             dependencies:
-                - intel-python/2020u2:python3 +                - miniconda/25.1.1.2 
-        "2.3.0:intel,python3.8": +        "2.17.0:cuda": 
-            description: 2.3.0 with Python 3.8, Intel optimizations+            description: 2.17.0 with CUDA support
             dependencies:             dependencies:
-                - intel-python/2020u2:python3+                - miniconda/25.1.1.2
 </file> </file>
  
Line 152: Line 148:
         - action: source         - action: source
           script:           script:
-              sh: anaconda-activate.sh+              sh: miniconda-activate.sh
           order: failure-first           order: failure-first
           success: 0           success: 0
     versions:     versions:
-        "2.2.0:gpu": +        "2.17.0:cpu": 
-            description: 2.2.0 with GPU support+            description: 2.17.0 with CPU support
             dependencies:             dependencies:
-                - intel-python/2020u2:python3 +                - miniconda/25.1.1.2 
-        "2.3.0:intel,python3.8": +        "2.17.0:cuda": 
-            description: 2.3.0 with Python 3.8, Intel optimizations+            description: 2.17.0 with CUDA support
             dependencies:             dependencies:
-                - intel-python/2020u2:python3+                - miniconda/25.1.1.2
         "1.8.0":         "1.8.0":
             description: 1.8.0 from pkgs/main             description: 1.8.0 from pkgs/main
             dependencies:             dependencies:
-                - intel-python/2018u3:python3+                - miniconda/25.1.1.2
 </file> </file>
  
Line 183: Line 179:
 [/work/my_workgroup/sw/valet/tensorflow.vpkg_yaml] [/work/my_workgroup/sw/valet/tensorflow.vpkg_yaml]
 tensorflow               TensorFlow Python environments tensorflow               TensorFlow Python environments
-* 2.2.0:gpu              2.2.0 with GPU support +* 2.17.0:cpu              2.17.0 with GPU support 
-  2.3.0:intel,python3.8  2.3.0 with Python 3.8, Intel optimizations+  2.17.0:cuda             2.17.0 with CUDA support
      
      :      :
Line 197: Line 193:
 # Setup TensorFlow virtualenv: # Setup TensorFlow virtualenv:
 # #
-vpkg_require tensorflow/2.3.0:intel,python3.8+vpkg_require tensorflow/2.17.0:cpu
  
 # #
  • technical/recipes/tensorflow-in-virtualenv.1761337611.txt.gz
  • Last modified: 2025-10-24 16:26
  • by thuachen