diff --git a/packages/py-arviz/package.py b/packages/py-arviz/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..c127d5f422b32fcd271fd38e90a8a883cb6e75f6
--- /dev/null
+++ b/packages/py-arviz/package.py
@@ -0,0 +1,36 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack.package import *
+
+
+class PyArviz(PythonPackage):
+    """ArviZ (pronounced "AR-vees") is a Python package for exploratory
+    analysis of Bayesian models. Includes functions for posterior analysis,
+    model checking, comparison and diagnostics."""
+
+    homepage = "https://github.com/arviz-devs/arviz"
+    pypi = "arviz/arviz-0.6.1.tar.gz"
+
+    license("Apache-2.0")
+
+    # begin EBRAINS (added): added version
+    version("0.20.0", sha256="a2704e0c141410fcaea1973a90cabf280f5aed5c1e10f44381ebd6c144c10a9c")
+    # end EBRAINS
+    version("0.6.1", sha256="435edf8db49c41a8fa198f959e7581063006c49a4efdef4755bb778db6fd4f72")
+
+    depends_on("py-setuptools", type="build")
+    depends_on("py-matplotlib@3.0:", type=("build", "run"))
+    depends_on("py-numpy@1.12:", type=("build", "run"))
+    depends_on("py-scipy@0.19:", type=("build", "run"))
+    depends_on("py-packaging", type=("build", "run"))
+    depends_on("py-pandas@0.23:", type=("build", "run"))
+    depends_on("py-xarray@0.11:", type=("build", "run"))
+    # begin EBRAINS (modified): update dependencies
+    depends_on("py-netcdf4", when="@:0.13", type=("build", "run"))
+    depends_on("py-h5netcdf", when="@0.15:", type=("build", "run"))
+    depends_on("py-typing-extensions", when="@0.11:", type=("build", "run"))
+    depends_on("py-xarray-einstats", type=("build", "run"))
+    # end EBRAINS
diff --git a/packages/py-cons/package.py b/packages/py-cons/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..77b2e1ab75a93b90f833d2a7106680c558c8d2de
--- /dev/null
+++ b/packages/py-cons/package.py
@@ -0,0 +1,19 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack import *
+
+
+class PyCons(PythonPackage):
+    """An implementation of cons in Python."""
+
+    homepage = "https://github.com/pythological/python-cons"
+    pypi = "cons/cons-0.4.6.tar.gz"
+
+    version("0.4.6", "669fe9d5ee916d5e42b9cac6acc911df803d04f2e945c1604982a04d27a29b47")
+
+    depends_on("python@3.6:", type=("build", "run"))
+    depends_on("py-setuptools", type="build")
+    depends_on("py-logical-unification@0.4.0:", type=("build", "run"))
diff --git a/packages/py-etuples/package.py b/packages/py-etuples/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..d3462437bf2ef7a81b7dc483c235230960249f98
--- /dev/null
+++ b/packages/py-etuples/package.py
@@ -0,0 +1,21 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack import *
+
+
+class PyEtuples(PythonPackage):
+    """Python library that allows one to define, optimize, and efficiently evaluate mathematical expressions involving
+    multi-dimensional arrays. It provides the computational backend for PyMC."""
+
+    homepage = "http://github.com/pythological/etuples"
+    pypi = "etuples/etuples-0.3.9.tar.gz"
+
+    version("0.3.9", "a474e586683d8ba8d842ba29305005ceed1c08371a4b4b0e0e232527137e5ea3")
+
+    depends_on("python@3.8:", type=("build", "run"))
+    depends_on("py-setuptools", type="build")
+    depends_on("py-cons", type=("build", "run"))
+    depends_on("py-multipledispatch", type=("build", "run"))
diff --git a/packages/py-joblib/package.py b/packages/py-joblib/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..41d5602ad1bb43608fd6db46b5a6a896b01d643d
--- /dev/null
+++ b/packages/py-joblib/package.py
@@ -0,0 +1,44 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack.package import *
+
+
+class PyJoblib(PythonPackage):
+    """Lightweight pipelining with Python functions."""
+
+    homepage = "https://joblib.readthedocs.io/"
+    pypi = "joblib/joblib-0.14.0.tar.gz"
+    git = "https://github.com/joblib/joblib"
+
+    # 'joblib.test' requires 'pytest'. Leave out of 'import_modules' to avoid
+    # unnecessary dependencies.
+    skip_modules = ["joblib.test"]
+
+    license("BSD-3-Clause")
+
+    # begin EBRAINS (added): add version
+    version("1.4.2", sha256="2382c5816b2636fbd20a09e0f4e9dad4736765fdfb7dca582943b9c1366b3f0e")
+    # end EBRAINS
+    version("1.2.0", sha256="e1cee4a79e4af22881164f218d4311f60074197fb707e082e803b61f6d137018")
+    version("1.1.0", sha256="4158fcecd13733f8be669be0683b96ebdbbd38d23559f54dca7205aea1bf1e35")
+    version("1.0.1", sha256="9c17567692206d2f3fb9ecf5e991084254fe631665c450b443761c4186a613f7")
+    version("1.0.0", sha256="7ad866067ac1fdec27d51c8678ea760601b70e32ff1881d4dc8e1171f2b64b24")
+    version("0.17.0", sha256="9e284edd6be6b71883a63c9b7f124738a3c16195513ad940eae7e3438de885d5")
+    version("0.16.0", sha256="8f52bf24c64b608bf0b2563e0e47d6fcf516abc8cfafe10cfd98ad66d94f92d6")
+    version("0.15.1", sha256="61e49189c84b3c5d99a969d314853f4d1d263316cc694bec17548ebaa9c47b6e")
+    version("0.15.0", sha256="f8f84dcef519233be4ede1c64fd1f2d48b1e8bbb632d1013ebca75f8b678ee72")
+    version("0.14.1", sha256="0630eea4f5664c463f23fbf5dcfc54a2bc6168902719fa8e19daf033022786c8")
+    version("0.14.0", sha256="6fcc57aacb4e89451fd449e9412687c51817c3f48662c3d8f38ba3f8a0a193ff")
+    version("0.13.2", sha256="315d6b19643ec4afd4c41c671f9f2d65ea9d787da093487a81ead7b0bac94524")
+    version("0.11", sha256="7b8fd56df36d9731a83729395ccb85a3b401f62a96255deb1a77220c00ed4085")
+    version("0.10.3", sha256="29b2965a9efbc90a5fe66a389ae35ac5b5b0c1feabfc7cab7fd5d19f429a071d")
+    version("0.10.2", sha256="3123553bdad83b143428033537c9e1939caf4a4d8813dade6a2246948c94494b")
+    version("0.10.0", sha256="49b3a0ba956eaa2f077e1ebd230b3c8d7b98afc67520207ada20a4d8b8efd071")
+
+    depends_on("python@3.7:", when="@1.2:", type=("build", "run"))
+    depends_on("python@3.6:", when="@0.15:", type=("build", "run"))
+    depends_on("python@2.7:2.8,3.4:", type=("build", "run"))
+    depends_on("py-setuptools", type=("build", "run"))
diff --git a/packages/py-logical-unification/package.py b/packages/py-logical-unification/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..7ba1620e4eac73cede7806e73f3648bf6a99a53b
--- /dev/null
+++ b/packages/py-logical-unification/package.py
@@ -0,0 +1,20 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack import *
+
+
+class PyLogicalUnification(PythonPackage):
+    """Logical unification in Python, extensible via dispatch."""
+
+    homepage = "http://github.com/pythological/unification/"
+    pypi = "logical-unification/logical-unification-0.4.6.tar.gz"
+
+    version("0.4.6", "908435123f8a106fa4dcf9bf1b75c7beb309fa2bbecf277868af8f1c212650a0")
+
+    depends_on("python@3.6:", type=("build", "run"))
+    depends_on("py-setuptools", type="build")
+    depends_on("py-toolz", type=("build", "run"))
+    depends_on("py-multipledispatch", type=("build", "run"))
diff --git a/packages/py-mini-kanren/package.py b/packages/py-mini-kanren/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..2d24eb02cdfad669bc3213da38ded284d27701b9
--- /dev/null
+++ b/packages/py-mini-kanren/package.py
@@ -0,0 +1,24 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack import *
+
+
+class PyMiniKanren(PythonPackage):
+    """Logic/relational programming in Python with miniKanren."""
+
+    homepage = "http://github.com/pythological/kanren"
+    pypi = "miniKanren/miniKanren-1.0.3.tar.gz"
+
+    version("1.0.3", "1ec8bdb01144ad5e8752c7c297fb8a122db920f859276d25a72d164e998d7f6e")
+
+    depends_on("python@3.6:", type=("build", "run"))
+    depends_on("py-setuptools", type="build")
+    depends_on("py-toolz", type=("build", "run"))
+    depends_on("py-cons@0.4.0:", type=("build", "run"))
+    depends_on("py-multipledispatch", type=("build", "run"))
+    depends_on("py-etuples@0.3.1:", type=("build", "run"))
+    depends_on("py-logical-unification@0.4.1:", type=("build", "run"))
+    depends_on("py-typing-extensions", type=("build", "run"))
diff --git a/packages/py-nflows/package.py b/packages/py-nflows/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..72f82caf53201553d401c127bdff0cffa99ea3a1
--- /dev/null
+++ b/packages/py-nflows/package.py
@@ -0,0 +1,22 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack import *
+
+class PyNflows(PythonPackage):
+    """It is a comprehensive collection of normalizing flows using PyTorch."""
+
+    homepage = "https://github.com/bayesiains/nflows"
+    pypi = "nflows/nflows-0.14.tar.gz"
+
+    version("0.14", "6299844a62f9999fcdf2d95cb2d01c091a50136bd17826e303aba646b2d11b55")
+
+    depends_on("py-setuptools", type="build")
+    depends_on("py-matplotlib", type=("build", "run"))
+    depends_on("py-numpy", type=("build", "run"))
+    depends_on("py-tensorboard", type=("build", "run"))
+    depends_on("py-torch", type=("build", "run"))
+    depends_on("py-tqdm", type=("build", "run"))
+    depends_on("py-umnn", type=("build", "run"))
diff --git a/packages/py-parameterized/package.py b/packages/py-parameterized/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..1ab006228c864a3961d2bac0f6a6c25e1ef21080
--- /dev/null
+++ b/packages/py-parameterized/package.py
@@ -0,0 +1,20 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack.package import *
+
+
+class PyParameterized(PythonPackage):
+    """Parameterized testing with any Python test framework."""
+
+    homepage = "https://github.com/wolever/parameterized"
+    pypi = "parameterized/parameterized-0.7.1.tar.gz"
+
+    # begin EBRAINS (added): new version
+    version("0.9.0", sha256="7fc905272cefa4f364c1a3429cbbe9c0f98b793988efb5bf90aac80f08db09b1")
+    # end EBRAINS
+    version("0.7.1", sha256="6a94dbea30c6abde99fd4c2f2042c1bf7f980e48908bf92ead62394f93cf57ed")
+
+    depends_on("py-setuptools", type="build")
diff --git a/packages/py-pycatch22/package.py b/packages/py-pycatch22/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..68c4be093beccec50bf5b4f096db249371d598f7
--- /dev/null
+++ b/packages/py-pycatch22/package.py
@@ -0,0 +1,16 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack import *
+
+
+class PyPycatch22(PythonPackage):
+    
+    homepage = "https://github.com/DynamicsAndNeuralSystems/pycatch22"
+    pypi="pycatch22/pycatch22-0.4.5.tar.gz"
+    
+    version("0.4.5", sha256="7ec844c659f22bedc66847ac866ef2bd86ffbbd4d8114b5e97f699f20a6f9f81")
+
+    depends_on("py-setuptools", type="build")
diff --git a/packages/py-pyknos/package.py b/packages/py-pyknos/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..e9449a6da430ac64be9ca1f1fe3128aa32843576
--- /dev/null
+++ b/packages/py-pyknos/package.py
@@ -0,0 +1,25 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack import *
+
+
+class PyPyknos(PythonPackage):
+    """Python package for conditional density estimation. It either wraps or implements diverse conditional density
+    estimators."""
+
+    homepage = "https://github.com/sbi-dev/pyknos"
+    pypi = "pyknos/pyknos-0.16.0.tar.gz"
+
+    version("0.16.0", "4e1db834d8a5fd847882a081937732fea6798668b72293ae052765e7bfc371c3")
+
+    depends_on("python@3.8:", type=("build", "run"))
+    depends_on("py-setuptools", type="build")
+    depends_on("py-matplotlib", type=("build", "run"))
+    depends_on("py-nflows@0.14", type=("build", "run"))
+    depends_on("py-numpy", type=("build", "run"))
+    depends_on("py-tensorboard", type=("build", "run"))
+    depends_on("py-torch", type=("build", "run"))
+    depends_on("py-tqdm", type=("build", "run"))
diff --git a/packages/py-pymc/package.py b/packages/py-pymc/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..b7dc999f41c53366467e19aa4cf65113b0dea464
--- /dev/null
+++ b/packages/py-pymc/package.py
@@ -0,0 +1,31 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack import *
+
+
+class PyPymc(PythonPackage):
+    """PyMC (formerly PyMC3) is a Python package for Bayesian statistical modeling focusing on advanced Markov chain Monte
+    Carlo (MCMC) and variational inference (VI) algorithms."""
+
+    homepage = "https://github.com/pymc-devs/pymc"
+    pypi = "pymc/pymc-5.20.1.tar.gz"
+
+    version("5.20.1", "fb5f20d196a1b34eb193a855c611887b2e7b98d3af37d8573a33d112e2278eac")
+
+    depends_on("python@3.10:", type=("build", "run"))
+    depends_on("py-setuptools", type="build")
+    depends_on("py-versioneer", type="build")
+
+    depends_on("py-arviz@0.13:", type=("build", "run"))
+    depends_on("py-cachetools@4.2.1:", type=("build", "run"))
+    depends_on("py-cloudpickle", type=("build", "run"))
+    depends_on("py-numpy@1.25.0:", type=("build", "run"))
+    depends_on("py-pandas@0.24.0:", type=("build", "run"))
+    depends_on("py-pytensor@2.26.1:2.27.999", type=("build", "run"))
+    depends_on("py-rich@13.7.1:", type=("build", "run"))
+    depends_on("py-scipy@1.4.1:", type=("build", "run"))
+    depends_on("py-threadpoolctl@3.1.0:3.99", type=("build", "run"))
+    depends_on("py-typing-extensions@3.7.4:", type=("build", "run"))
diff --git a/packages/py-pytensor/package.py b/packages/py-pytensor/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..4c04539334675f9185af0f5a10aadae5b8c07cdd
--- /dev/null
+++ b/packages/py-pytensor/package.py
@@ -0,0 +1,27 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack import *
+
+class PyPytensor(PythonPackage):
+    """Python library that allows one to define, optimize, and efficiently evaluate mathematical expressions involving
+    multi-dimensional arrays. It provides the computational backend for PyMC."""
+
+    homepage = "https://github.com/pymc-devs/pytensor"
+    pypi = "pytensor/pytensor-2.27.1.tar.gz"
+
+    version("2.27.1", "ed5075e1504e0e4c2322340111289820c5e1718b70187922777d560a8ef26f75")
+
+    depends_on("python@3.10:3.13", type=("build", "run"))
+    depends_on("py-setuptools@59.0.0:", type="build")
+    depends_on("py-cython", type="build")
+    depends_on("py-versioneer+toml", type="build")
+    depends_on("py-scipy@1.0:1", type=("build", "run"))
+    depends_on("py-numpy@1.17.0:", type=("build", "run"))
+    depends_on("py-filelock", type=("build", "run")) # TODO: it needs filelock>=3.15, but on pypi the latest one is 3.12.4
+    depends_on("py-etuples", type=("build", "run"))
+    depends_on("py-logical-unification", type=("build", "run"))
+    depends_on("py-mini-kanren", type=("build", "run"))
+    depends_on("py-cons", type=("build", "run"))
diff --git a/packages/py-sbi/package.py b/packages/py-sbi/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..a560cd93431e33171296d3d6019fb1c4eade6851
--- /dev/null
+++ b/packages/py-sbi/package.py
@@ -0,0 +1,46 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack import *
+
+
+class PySbi(PythonPackage):
+    """Python package for simulating biological systems."""
+
+    homepage = "https://sbi-dev.github.io/sbi/v0.23.3/"
+    url = "https://github.com/sbi-dev/sbi/archive/refs/tags/v0.23.3.tar.gz"
+
+    version("0.23.3", "b1ef102e47c90088f2adfff5ea88b18421e84c4641ff4dd4f68c1116c296ba81")
+
+    depends_on("python@3.9:", type=("build", "run"))
+    depends_on("py-setuptools", type="build")
+    depends_on("py-wheel", type="build")
+
+    depends_on("py-arviz", type=("build", "run"))
+    depends_on("py-joblib@1.3.0:", type=("build", "run"))
+    depends_on("py-matplotlib", type=("build", "run"))
+    depends_on("py-notebook@:6.4.12", type=("build", "run"))
+    depends_on("py-numpy@:1", type=("build", "run"))
+    depends_on("py-pillow", type=("build", "run"))
+    depends_on("py-pyknos@0.16.0:", type=("build", "run"))
+    depends_on("py-pyro-ppl@1.3.1:", type=("build", "run"))
+    depends_on("py-scikit-learn", type=("build", "run"))
+    depends_on("py-scipy", type=("build", "run"))
+    depends_on("py-tensorboard", type=("build", "run"))
+    depends_on("py-torch@1.13.0:", type=("build", "run"))
+    depends_on("py-tqdm", type=("build", "run"))
+    depends_on("py-pymc@5.0.0:", type=("build", "run"))
+    depends_on("py-zuko@1.2.0:", type=("build", "run"))
+
+    depends_on("py-pytest", type="test")
+    depends_on("py-torchtestcase", type="test")
+
+    skip_modules = ["sbi.inference.snle", "sbi.inference.snpe", "sbi.inference.snre", "sbi.samplers.score", "sbi.samplers.vi"]
+
+    @run_after("install")
+    @on_package_attributes(run_tests=True)
+    def install_test(self):
+        pytest = which("pytest")
+        pytest("-m", "not slow and not gpu")
diff --git a/packages/py-torch/detect_omp_of_fujitsu_compiler.patch b/packages/py-torch/detect_omp_of_fujitsu_compiler.patch
new file mode 100644
index 0000000000000000000000000000000000000000..519d66869d578ea4a59c4e7f626569baade6837a
--- /dev/null
+++ b/packages/py-torch/detect_omp_of_fujitsu_compiler.patch
@@ -0,0 +1,20 @@
+--- pytorch/cmake/Modules/FindOpenMP.cmake.org	2020-05-26 17:43:53.000000000 +0900
++++ pytorch/cmake/Modules/FindOpenMP.cmake	2020-05-26 17:46:37.000000000 +0900
+@@ -84,7 +84,7 @@
+     unset(OpenMP_FLAG_CANDIDATES)
+ 
+     set(OMP_FLAG_GNU "-fopenmp")
+-    set(OMP_FLAG_Clang "-fopenmp=libomp" "-fopenmp=libiomp5" "-fopenmp")
++    set(OMP_FLAG_Clang "-fopenmp" "-fopenmp=libomp" "-fopenmp=libiomp5")
+ 
+     # AppleClang may need a header file, search for omp.h with hints to brew
+     # default include dir
+@@ -245,7 +245,7 @@
+         set(OpenMP_libomp_LIBRARY "${MKL_OPENMP_LIBRARY}" CACHE STRING "libomp location for OpenMP")
+       else()
+         find_library(OpenMP_libomp_LIBRARY
+-          NAMES omp gomp iomp5
++          NAMES fjomp omp gomp iomp5
+           HINTS ${CMAKE_${LANG}_IMPLICIT_LINK_DIRECTORIES}
+           DOC "libomp location for OpenMP"
+         )
diff --git a/packages/py-torch/fj-ssl2_1.10.patch b/packages/py-torch/fj-ssl2_1.10.patch
new file mode 100644
index 0000000000000000000000000000000000000000..bcd2c37804c1ba1ee62d70907c8705a23607a5aa
--- /dev/null
+++ b/packages/py-torch/fj-ssl2_1.10.patch
@@ -0,0 +1,76 @@
+diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake
+index ca560288a4..f5a29ecf43 100644
+--- a/cmake/Dependencies.cmake
++++ b/cmake/Dependencies.cmake
+@@ -130,7 +130,7 @@ else()
+   set(AT_MKLDNN_ENABLED 0)
+   set(AT_MKL_ENABLED 0)
+ endif()
+-set_property(CACHE BLAS PROPERTY STRINGS "ATLAS;BLIS;Eigen;FLAME;Generic;MKL;OpenBLAS;vecLib")
++set_property(CACHE BLAS PROPERTY STRINGS "ATLAS;BLIS;Eigen;FLAME;Generic;MKL;OpenBLAS;SSL2;vecLib")
+ message(STATUS "Trying to find preferred BLAS backend of choice: " ${BLAS})
+ 
+ if(BLAS STREQUAL "Eigen")
+@@ -185,6 +185,20 @@ elseif(BLAS STREQUAL "vecLib")
+   set(BLAS_INFO "veclib")
+   set(BLAS_FOUND 1)
+   set(BLAS_LIBRARIES ${vecLib_LINKER_LIBS})
++elseif(BLAS STREQUAL "SSL2")
++  if(CMAKE_CXX_COMPILER MATCHES ".*/FCC$"
++      AND CMAKE_C_COMPILER MATCHES ".*/fcc$")
++    message(STATUS "SSL2 Selected BLAS library")
++    list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS "fjlapackexsve.so")
++    set(SSL2_FOUND ON)
++    message(STATUS "set CMAKE_SHARED_LINKER_FLAGS: -SSL2 --linkfortran")
++    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -SSL2 --linkfortran")
++    set(WITH_BLAS "ssl2")
++  else()
++    message(STATUS "Not built using fcc and FCC.")
++    message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
++    message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
++  endif()
+ elseif(BLAS STREQUAL "Generic")
+   # On Debian family, the CBLAS ABIs have been merged into libblas.so
+   find_library(BLAS_LIBRARIES blas)
+@@ -201,7 +215,7 @@ if(NOT INTERN_BUILD_MOBILE)
+   set(AT_MKL_ENABLED 0)
+   set(AT_MKL_MT 0)
+   set(USE_BLAS 1)
+-  if(NOT (ATLAS_FOUND OR BLIS_FOUND OR GENERIC_BLAS_FOUND OR MKL_FOUND OR OpenBLAS_FOUND OR VECLIB_FOUND))
++  if(NOT (ATLAS_FOUND OR BLIS_FOUND OR GENERIC_BLAS_FOUND OR MKL_FOUND OR OpenBLAS_FOUND OR SSL2_FOUND OR VECLIB_FOUND))
+     message(WARNING "Preferred BLAS (" ${BLAS} ") cannot be found, now searching for a general BLAS library")
+     find_package(BLAS)
+     if(NOT BLAS_FOUND)
+diff --git a/cmake/Modules/FindBLAS.cmake b/cmake/Modules/FindBLAS.cmake
+index 47c80b45f6..efd4a87d06 100644
+--- a/cmake/Modules/FindBLAS.cmake
++++ b/cmake/Modules/FindBLAS.cmake
+@@ -276,6 +276,28 @@ if((NOT BLAS_LIBRARIES)
+   endif()
+ endif()
+ 
++# BLAS in SSL2 library?
++if((NOT BLAS_LIBRARIES)
++    AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "ssl2")))
++  if(CMAKE_CXX_COMPILER MATCHES ".*/FCC$"
++      AND CMAKE_C_COMPILER MATCHES ".*/fcc$")
++    check_fortran_libraries(
++    BLAS_LIBRARIES
++    BLAS
++    sgemm
++    "-SSL2;--linkfortran"
++    "fjlapackexsve")
++    if (BLAS_LIBRARIES)
++      set(BLAS_INFO "ssl2")
++      set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -SSL2 --linkfortran")
++    endif (BLAS_LIBRARIES)
++  else()
++    message(STATUS "Not built using fcc and FCC.")
++    message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
++    message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
++  endif()
++endif()
++
+ # Generic BLAS library?
+ if((NOT BLAS_LIBRARIES)
+     AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "generic")))
diff --git a/packages/py-torch/fj-ssl2_1.11.patch b/packages/py-torch/fj-ssl2_1.11.patch
new file mode 100644
index 0000000000000000000000000000000000000000..af41e5bb93931ca3c0f12a55733407a52fb4af31
--- /dev/null
+++ b/packages/py-torch/fj-ssl2_1.11.patch
@@ -0,0 +1,76 @@
+diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake
+index 557ab649a4..56d1699736 100644
+--- a/cmake/Dependencies.cmake
++++ b/cmake/Dependencies.cmake
+@@ -174,7 +174,7 @@ else()
+   set(AT_MKLDNN_ENABLED 0)
+   set(AT_MKL_ENABLED 0)
+ endif()
+-set_property(CACHE BLAS PROPERTY STRINGS "ATLAS;BLIS;Eigen;FLAME;Generic;MKL;OpenBLAS;vecLib")
++set_property(CACHE BLAS PROPERTY STRINGS "ATLAS;BLIS;Eigen;FLAME;Generic;MKL;OpenBLAS;SSL2;vecLib")
+ message(STATUS "Trying to find preferred BLAS backend of choice: " ${BLAS})
+ 
+ if(BLAS STREQUAL "Eigen")
+@@ -229,6 +229,20 @@ elseif(BLAS STREQUAL "vecLib")
+   set(BLAS_INFO "veclib")
+   set(BLAS_FOUND 1)
+   set(BLAS_LIBRARIES ${vecLib_LINKER_LIBS})
++elseif(BLAS STREQUAL "SSL2")
++  if(CMAKE_CXX_COMPILER MATCHES ".*/FCC$"
++      AND CMAKE_C_COMPILER MATCHES ".*/fcc$")
++    message(STATUS "SSL2 Selected BLAS library")
++    list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS "fjlapackexsve.so")
++    set(SSL2_FOUND ON)
++    message(STATUS "set CMAKE_SHARED_LINKER_FLAGS: -SSL2 --linkfortran")
++    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -SSL2 --linkfortran")
++    set(WITH_BLAS "ssl2")
++  else()
++    message(STATUS "Not built using fcc and FCC.")
++    message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
++    message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
++  endif()
+ elseif(BLAS STREQUAL "FlexiBLAS")
+   find_package(FlexiBLAS REQUIRED)
+   include_directories(SYSTEM ${FlexiBLAS_INCLUDE_DIR})
+@@ -250,7 +264,7 @@ if(NOT INTERN_BUILD_MOBILE)
+   set(AT_MKL_SEQUENTIAL 0)
+   set(AT_MKL_MT 0)
+   set(USE_BLAS 1)
+-  if(NOT (ATLAS_FOUND OR BLIS_FOUND OR GENERIC_BLAS_FOUND OR MKL_FOUND OR OpenBLAS_FOUND OR VECLIB_FOUND OR FlexiBLAS_FOUND))
++  if(NOT (ATLAS_FOUND OR BLIS_FOUND OR GENERIC_BLAS_FOUND OR MKL_FOUND OR OpenBLAS_FOUND OR SSL2_FOUND OR VECLIB_FOUND OR FlexiBLAS_FOUND))
+     message(WARNING "Preferred BLAS (" ${BLAS} ") cannot be found, now searching for a general BLAS library")
+     find_package(BLAS)
+     if(NOT BLAS_FOUND)
+diff --git a/cmake/Modules/FindBLAS.cmake b/cmake/Modules/FindBLAS.cmake
+index 94942d520f..ae5b8db963 100644
+--- a/cmake/Modules/FindBLAS.cmake
++++ b/cmake/Modules/FindBLAS.cmake
+@@ -289,6 +289,28 @@ if((NOT BLAS_LIBRARIES)
+   endif()
+ endif()
+ 
++# BLAS in SSL2 library?
++if((NOT BLAS_LIBRARIES)
++    AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "ssl2")))
++  if(CMAKE_CXX_COMPILER MATCHES ".*/FCC$"
++      AND CMAKE_C_COMPILER MATCHES ".*/fcc$")
++    check_fortran_libraries(
++    BLAS_LIBRARIES
++    BLAS
++    sgemm
++    "-SSL2;--linkfortran"
++    "fjlapackexsve")
++    if (BLAS_LIBRARIES)
++      set(BLAS_INFO "ssl2")
++      set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -SSL2 --linkfortran")
++    endif (BLAS_LIBRARIES)
++  else()
++    message(STATUS "Not built using fcc and FCC.")
++    message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
++    message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
++  endif()
++endif()
++
+ # Generic BLAS library?
+ if((NOT BLAS_LIBRARIES)
+     AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "generic")))
diff --git a/packages/py-torch/fj-ssl2_1.3-1.5.patch b/packages/py-torch/fj-ssl2_1.3-1.5.patch
new file mode 100644
index 0000000000000000000000000000000000000000..0ea87500b0a60e35450c90315c5466d5f6488073
--- /dev/null
+++ b/packages/py-torch/fj-ssl2_1.3-1.5.patch
@@ -0,0 +1,76 @@
+diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake
+index a8e9769536..f0f91304c2 100644
+--- a/cmake/Dependencies.cmake
++++ b/cmake/Dependencies.cmake
+@@ -107,7 +107,7 @@ else()
+   set(AT_MKLDNN_ENABLED 0)
+   set(AT_MKL_ENABLED 0)
+ endif()
+-set_property(CACHE BLAS PROPERTY STRINGS "Eigen;ATLAS;OpenBLAS;MKL;vecLib;FLAME")
++set_property(CACHE BLAS PROPERTY STRINGS "Eigen;ATLAS;OpenBLAS;MKL;vecLib;SSL2;FLAME")
+ message(STATUS "Trying to find preferred BLAS backend of choice: " ${BLAS})
+ 
+ if(BLAS STREQUAL "Eigen")
+@@ -147,6 +147,20 @@ elseif(BLAS STREQUAL "vecLib")
+   find_package(vecLib REQUIRED)
+   include_directories(SYSTEM ${vecLib_INCLUDE_DIR})
+   list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS ${vecLib_LINKER_LIBS})
++elseif(BLAS STREQUAL "SSL2")
++  if(CMAKE_CXX_COMPILER MATCHES ".*/FCC$"
++      AND CMAKE_C_COMPILER MATCHES ".*/fcc$")
++    message(STATUS "SSL2 Selected BLAS library")
++    list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS "fjlapackexsve.so")
++    set(SSL2_FOUND ON)
++    message(STATUS "set CMAKE_SHARED_LINKER_FLAGS: -SSL2 --linkfortran")
++    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -SSL2 --linkfortran")
++    set(WITH_BLAS "ssl2")
++  else()
++    message(STATUS "Not built using fcc and FCC.")
++    message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
++    message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
++  endif()
+ else()
+   message(FATAL_ERROR "Unrecognized BLAS option: " ${BLAS})
+ endif()
+@@ -156,7 +170,7 @@ if (NOT INTERN_BUILD_MOBILE)
+   set(AT_MKL_ENABLED 0)
+   set(AT_MKL_MT 0)
+   set(USE_BLAS 1)
+-  if(NOT (ATLAS_FOUND OR OpenBLAS_FOUND OR MKL_FOUND OR VECLIB_FOUND))
++  if(NOT (ATLAS_FOUND OR OpenBLAS_FOUND OR MKL_FOUND OR VECLIB_FOUND OR SSL2_FOUND))
+     message(WARNING "Preferred BLAS (" ${BLAS} ") cannot be found, now searching for a general BLAS library")
+     find_package(BLAS)
+     if (NOT BLAS_FOUND)
+diff --git a/cmake/Modules/FindBLAS.cmake b/cmake/Modules/FindBLAS.cmake
+index e93e98a609..d43a6c40bd 100644
+--- a/cmake/Modules/FindBLAS.cmake
++++ b/cmake/Modules/FindBLAS.cmake
+@@ -239,6 +239,28 @@ if((NOT BLAS_LIBRARIES)
+   endif (BLAS_LIBRARIES)
+ endif()
+ 
++# BLAS in SSL2 library?
++if((NOT BLAS_LIBRARIES)
++    AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "ssl2")))
++  if(CMAKE_CXX_COMPILER MATCHES ".*/FCC$"
++      AND CMAKE_C_COMPILER MATCHES ".*/fcc$")
++    check_fortran_libraries(
++    BLAS_LIBRARIES
++    BLAS
++    sgemm
++    "-SSL2;--linkfortran"
++    "fjlapackexsve")
++    if (BLAS_LIBRARIES)
++      set(BLAS_INFO "ssl2")
++      set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -SSL2 --linkfortran")
++    endif (BLAS_LIBRARIES)
++  else()
++    message(STATUS "Not built using fcc and FCC.")
++    message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
++    message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
++  endif()
++endif()
++
+ # Generic BLAS library?
+ if((NOT BLAS_LIBRARIES)
+     AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "generic")))
diff --git a/packages/py-torch/fj-ssl2_1.6-1.7.patch b/packages/py-torch/fj-ssl2_1.6-1.7.patch
new file mode 100644
index 0000000000000000000000000000000000000000..423af3f21299395696d27703e531c504c19b50f4
--- /dev/null
+++ b/packages/py-torch/fj-ssl2_1.6-1.7.patch
@@ -0,0 +1,76 @@
+diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake
+index 36e1ab7682..0f02f51c47 100644
+--- a/cmake/Dependencies.cmake
++++ b/cmake/Dependencies.cmake
+@@ -114,7 +114,7 @@ else()
+   set(AT_MKLDNN_ENABLED 0)
+   set(AT_MKL_ENABLED 0)
+ endif()
+-set_property(CACHE BLAS PROPERTY STRINGS "Eigen;ATLAS;OpenBLAS;MKL;vecLib;FLAME;Generic")
++set_property(CACHE BLAS PROPERTY STRINGS "Eigen;ATLAS;OpenBLAS;MKL;vecLib;SSL2;FLAME;Generic")
+ message(STATUS "Trying to find preferred BLAS backend of choice: " ${BLAS})
+ 
+ if(BLAS STREQUAL "Eigen")
+@@ -154,6 +154,20 @@ elseif(BLAS STREQUAL "vecLib")
+   find_package(vecLib REQUIRED)
+   include_directories(SYSTEM ${vecLib_INCLUDE_DIR})
+   list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS ${vecLib_LINKER_LIBS})
++elseif(BLAS STREQUAL "SSL2")
++  if(CMAKE_CXX_COMPILER MATCHES ".*/FCC$"
++      AND CMAKE_C_COMPILER MATCHES ".*/fcc$")
++    message(STATUS "SSL2 Selected BLAS library")
++    list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS "fjlapackexsve.so")
++    set(SSL2_FOUND ON)
++    message(STATUS "set CMAKE_SHARED_LINKER_FLAGS: -SSL2 --linkfortran")
++    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -SSL2 --linkfortran")
++    set(WITH_BLAS "ssl2")
++  else()
++    message(STATUS "Not built using fcc and FCC.")
++    message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
++    message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
++  endif()
+ elseif(BLAS STREQUAL "Generic")
+   # On Debian family, the CBLAS ABIs have been merged into libblas.so
+   find_library(BLAS_LIBRARIES blas)
+@@ -168,7 +182,7 @@ if(NOT INTERN_BUILD_MOBILE)
+   set(AT_MKL_ENABLED 0)
+   set(AT_MKL_MT 0)
+   set(USE_BLAS 1)
+-  if(NOT (ATLAS_FOUND OR OpenBLAS_FOUND OR MKL_FOUND OR VECLIB_FOUND OR GENERIC_BLAS_FOUND))
++  if(NOT (ATLAS_FOUND OR OpenBLAS_FOUND OR MKL_FOUND OR VECLIB_FOUND OR SSL2_FOUND OR GENERIC_BLAS_FOUND))
+     message(WARNING "Preferred BLAS (" ${BLAS} ") cannot be found, now searching for a general BLAS library")
+     find_package(BLAS)
+     if(NOT BLAS_FOUND)
+diff --git a/cmake/Modules/FindBLAS.cmake b/cmake/Modules/FindBLAS.cmake
+index e93e98a609..d43a6c40bd 100644
+--- a/cmake/Modules/FindBLAS.cmake
++++ b/cmake/Modules/FindBLAS.cmake
+@@ -239,6 +239,28 @@ if((NOT BLAS_LIBRARIES)
+   endif (BLAS_LIBRARIES)
+ endif()
+ 
++# BLAS in SSL2 library?
++if((NOT BLAS_LIBRARIES)
++    AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "ssl2")))
++  if(CMAKE_CXX_COMPILER MATCHES ".*/FCC$"
++      AND CMAKE_C_COMPILER MATCHES ".*/fcc$")
++    check_fortran_libraries(
++    BLAS_LIBRARIES
++    BLAS
++    sgemm
++    "-SSL2;--linkfortran"
++    "fjlapackexsve")
++    if (BLAS_LIBRARIES)
++      set(BLAS_INFO "ssl2")
++      set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -SSL2 --linkfortran")
++    endif (BLAS_LIBRARIES)
++  else()
++    message(STATUS "Not built using fcc and FCC.")
++    message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
++    message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
++  endif()
++endif()
++
+ # Generic BLAS library?
+ if((NOT BLAS_LIBRARIES)
+     AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "generic")))
diff --git a/packages/py-torch/fj-ssl2_1.8.patch b/packages/py-torch/fj-ssl2_1.8.patch
new file mode 100644
index 0000000000000000000000000000000000000000..461c1a2976b7a118173182452075e809f7f52858
--- /dev/null
+++ b/packages/py-torch/fj-ssl2_1.8.patch
@@ -0,0 +1,76 @@
+diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake
+index 06464e799a..7f50bd8fa0 100644
+--- a/cmake/Dependencies.cmake
++++ b/cmake/Dependencies.cmake
+@@ -118,7 +118,7 @@ else()
+   set(AT_MKLDNN_ENABLED 0)
+   set(AT_MKL_ENABLED 0)
+ endif()
+-set_property(CACHE BLAS PROPERTY STRINGS "Eigen;ATLAS;OpenBLAS;MKL;vecLib;FLAME;Generic")
++set_property(CACHE BLAS PROPERTY STRINGS "Eigen;ATLAS;OpenBLAS;MKL;vecLib;SSL2;FLAME;Generic")
+ message(STATUS "Trying to find preferred BLAS backend of choice: " ${BLAS})
+ 
+ if(BLAS STREQUAL "Eigen")
+@@ -157,6 +157,20 @@ elseif(BLAS STREQUAL "vecLib")
+   find_package(vecLib REQUIRED)
+   include_directories(SYSTEM ${vecLib_INCLUDE_DIR})
+   list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS ${vecLib_LINKER_LIBS})
++elseif(BLAS STREQUAL "SSL2")
++  if(CMAKE_CXX_COMPILER MATCHES ".*/FCC$"
++      AND CMAKE_C_COMPILER MATCHES ".*/fcc$")
++    message(STATUS "SSL2 Selected BLAS library")
++    list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS "fjlapackexsve.so")
++    set(SSL2_FOUND ON)
++    message(STATUS "set CMAKE_SHARED_LINKER_FLAGS: -SSL2 --linkfortran")
++    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -SSL2 --linkfortran")
++    set(WITH_BLAS "ssl2")
++  else()
++    message(STATUS "Not built using fcc and FCC.")
++    message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
++    message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
++  endif()
+ elseif(BLAS STREQUAL "Generic")
+   # On Debian family, the CBLAS ABIs have been merged into libblas.so
+   find_library(BLAS_LIBRARIES blas)
+@@ -171,7 +185,7 @@ if(NOT INTERN_BUILD_MOBILE)
+   set(AT_MKL_ENABLED 0)
+   set(AT_MKL_MT 0)
+   set(USE_BLAS 1)
+-  if(NOT (ATLAS_FOUND OR OpenBLAS_FOUND OR MKL_FOUND OR VECLIB_FOUND OR GENERIC_BLAS_FOUND))
++  if(NOT (ATLAS_FOUND OR OpenBLAS_FOUND OR MKL_FOUND OR VECLIB_FOUND OR SSL2_FOUND OR GENERIC_BLAS_FOUND))
+     message(WARNING "Preferred BLAS (" ${BLAS} ") cannot be found, now searching for a general BLAS library")
+     find_package(BLAS)
+     if(NOT BLAS_FOUND)
+diff --git a/cmake/Modules/FindBLAS.cmake b/cmake/Modules/FindBLAS.cmake
+index e8f5d7c950..29219e057f 100644
+--- a/cmake/Modules/FindBLAS.cmake
++++ b/cmake/Modules/FindBLAS.cmake
+@@ -257,6 +257,28 @@ if((NOT BLAS_LIBRARIES)
+   endif()
+ endif()
+ 
++# BLAS in SSL2 library?
++if((NOT BLAS_LIBRARIES)
++    AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "ssl2")))
++  if(CMAKE_CXX_COMPILER MATCHES ".*/FCC$"
++      AND CMAKE_C_COMPILER MATCHES ".*/fcc$")
++    check_fortran_libraries(
++    BLAS_LIBRARIES
++    BLAS
++    sgemm
++    "-SSL2;--linkfortran"
++    "fjlapackexsve")
++    if (BLAS_LIBRARIES)
++      set(BLAS_INFO "ssl2")
++      set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -SSL2 --linkfortran")
++    endif (BLAS_LIBRARIES)
++  else()
++    message(STATUS "Not built using fcc and FCC.")
++    message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
++    message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
++  endif()
++endif()
++
+ # Generic BLAS library?
+ if((NOT BLAS_LIBRARIES)
+     AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "generic")))
diff --git a/packages/py-torch/fj-ssl2_1.9.patch b/packages/py-torch/fj-ssl2_1.9.patch
new file mode 100644
index 0000000000000000000000000000000000000000..0febb57586fc1297ac21c1707e1c9cfc93da819d
--- /dev/null
+++ b/packages/py-torch/fj-ssl2_1.9.patch
@@ -0,0 +1,76 @@
+diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake
+index 5d57b9ca78..a74fe73b9f 100644
+--- a/cmake/Dependencies.cmake
++++ b/cmake/Dependencies.cmake
+@@ -118,7 +118,7 @@ else()
+   set(AT_MKLDNN_ENABLED 0)
+   set(AT_MKL_ENABLED 0)
+ endif()
+-set_property(CACHE BLAS PROPERTY STRINGS "ATLAS;BLIS;Eigen;FLAME;Generic;MKL;OpenBLAS;vecLib")
++set_property(CACHE BLAS PROPERTY STRINGS "ATLAS;BLIS;Eigen;FLAME;Generic;MKL;OpenBLAS;SSL2;vecLib")
+ message(STATUS "Trying to find preferred BLAS backend of choice: " ${BLAS})
+ 
+ if(BLAS STREQUAL "Eigen")
+@@ -161,6 +161,20 @@ elseif(BLAS STREQUAL "vecLib")
+   find_package(vecLib REQUIRED)
+   include_directories(SYSTEM ${vecLib_INCLUDE_DIR})
+   list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS ${vecLib_LINKER_LIBS})
++elseif(BLAS STREQUAL "SSL2")
++  if(CMAKE_CXX_COMPILER MATCHES ".*/FCC$"
++      AND CMAKE_C_COMPILER MATCHES ".*/fcc$")
++    message(STATUS "SSL2 Selected BLAS library")
++    list(APPEND Caffe2_PUBLIC_DEPENDENCY_LIBS "fjlapackexsve.so")
++    set(SSL2_FOUND ON)
++    message(STATUS "set CMAKE_SHARED_LINKER_FLAGS: -SSL2 --linkfortran")
++    set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -SSL2 --linkfortran")
++    set(WITH_BLAS "ssl2")
++  else()
++    message(STATUS "Not built using fcc and FCC.")
++    message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
++    message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
++  endif()
+ elseif(BLAS STREQUAL "Generic")
+   # On Debian family, the CBLAS ABIs have been merged into libblas.so
+   find_library(BLAS_LIBRARIES blas)
+@@ -175,7 +189,7 @@ if(NOT INTERN_BUILD_MOBILE)
+   set(AT_MKL_ENABLED 0)
+   set(AT_MKL_MT 0)
+   set(USE_BLAS 1)
+-  if(NOT (ATLAS_FOUND OR BLIS_FOUND OR GENERIC_BLAS_FOUND OR MKL_FOUND OR OpenBLAS_FOUND OR VECLIB_FOUND))
++  if(NOT (ATLAS_FOUND OR BLIS_FOUND OR GENERIC_BLAS_FOUND OR MKL_FOUND OR OpenBLAS_FOUND OR SSL2_FOUND OR VECLIB_FOUND))
+     message(WARNING "Preferred BLAS (" ${BLAS} ") cannot be found, now searching for a general BLAS library")
+     find_package(BLAS)
+     if(NOT BLAS_FOUND)
+diff --git a/cmake/Modules/FindBLAS.cmake b/cmake/Modules/FindBLAS.cmake
+index eefd6d475a..92ad75d32e 100644
+--- a/cmake/Modules/FindBLAS.cmake
++++ b/cmake/Modules/FindBLAS.cmake
+@@ -276,6 +276,28 @@ if((NOT BLAS_LIBRARIES)
+   endif()
+ endif()
+ 
++# BLAS in SSL2 library?
++if((NOT BLAS_LIBRARIES)
++    AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "ssl2")))
++  if(CMAKE_CXX_COMPILER MATCHES ".*/FCC$"
++      AND CMAKE_C_COMPILER MATCHES ".*/fcc$")
++    check_fortran_libraries(
++    BLAS_LIBRARIES
++    BLAS
++    sgemm
++    "-SSL2;--linkfortran"
++    "fjlapackexsve")
++    if (BLAS_LIBRARIES)
++      set(BLAS_INFO "ssl2")
++      set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -SSL2 --linkfortran")
++    endif (BLAS_LIBRARIES)
++  else()
++    message(STATUS "Not built using fcc and FCC.")
++    message(STATUS "CMAKE_C_COMPILER: ${CMAKE_C_COMPILER}")
++    message(STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
++  endif()
++endif()
++
+ # Generic BLAS library?
+ if((NOT BLAS_LIBRARIES)
+     AND ((NOT WITH_BLAS) OR (WITH_BLAS STREQUAL "generic")))
diff --git a/packages/py-torch/package.py b/packages/py-torch/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..b274723b83414cbe1f3e13714d6441f16b33d64d
--- /dev/null
+++ b/packages/py-torch/package.py
@@ -0,0 +1,715 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+import os
+import sys
+
+from spack.operating_systems.mac_os import macos_version
+from spack.package import *
+
+
+class PyTorch(PythonPackage, CudaPackage, ROCmPackage):
+    """Tensors and Dynamic neural networks in Python with strong GPU acceleration."""
+
+    homepage = "https://pytorch.org/"
+    git = "https://github.com/pytorch/pytorch.git"
+    submodules = True
+
+    # Exact set of modules is version- and variant-specific, just attempt to import the
+    # core libraries to ensure that the package was successfully installed.
+    import_modules = ["torch", "torch.autograd", "torch.nn", "torch.utils"]
+
+    license("BSD-3-Clause")
+    maintainers("adamjstewart")
+
+    version("main", branch="main")
+    version("2.5.1", tag="v2.5.1", commit="a8d6afb511a69687bbb2b7e88a3cf67917e1697e")
+    version("2.5.0", tag="v2.5.0", commit="32f585d9346e316e554c8d9bf7548af9f62141fc")
+    version("2.4.1", tag="v2.4.1", commit="ee1b6804381c57161c477caa380a840a84167676")
+    version("2.4.0", tag="v2.4.0", commit="d990dada86a8ad94882b5c23e859b88c0c255bda")
+    version("2.3.1", tag="v2.3.1", commit="63d5e9221bedd1546b7d364b5ce4171547db12a9")
+    version("2.3.0", tag="v2.3.0", commit="97ff6cfd9c86c5c09d7ce775ab64ec5c99230f5d")
+    version("2.2.2", tag="v2.2.2", commit="39901f229520a5256505ec24782f716ee7ddc843")
+    version("2.2.1", tag="v2.2.1", commit="6c8c5ad5eaf47a62fafbb4a2747198cbffbf1ff0")
+    version("2.2.0", tag="v2.2.0", commit="8ac9b20d4b090c213799e81acf48a55ea8d437d6")
+    version("2.1.2", tag="v2.1.2", commit="a8e7c98cb95ff97bb30a728c6b2a1ce6bff946eb")
+    version("2.1.1", tag="v2.1.1", commit="4c55dc50355d5e923642c59ad2a23d6ad54711e7")
+    version("2.1.0", tag="v2.1.0", commit="7bcf7da3a268b435777fe87c7794c382f444e86d")
+    version("2.0.1", tag="v2.0.1", commit="e9ebda29d87ce0916ab08c06ab26fd3766a870e5")
+    version("2.0.0", tag="v2.0.0", commit="c263bd43e8e8502d4726643bc6fd046f0130ac0e")
+    version("1.13.1", tag="v1.13.1", commit="49444c3e546bf240bed24a101e747422d1f8a0ee")
+    version("1.13.0", tag="v1.13.0", commit="7c98e70d44abc7a1aead68b6ea6c8adc8c554db5")
+    version("1.12.1", tag="v1.12.1", commit="664058fa83f1d8eede5d66418abff6e20bd76ca8")
+    version("1.12.0", tag="v1.12.0", commit="67ece03c8cd632cce9523cd96efde6f2d1cc8121")
+    version("1.11.0", tag="v1.11.0", commit="bc2c6edaf163b1a1330e37a6e34caf8c553e4755")
+    version("1.10.2", tag="v1.10.2", commit="71f889c7d265b9636b93ede9d651c0a9c4bee191")
+    version("1.10.1", tag="v1.10.1", commit="302ee7bfb604ebef384602c56e3853efed262030")
+    version("1.10.0", tag="v1.10.0", commit="36449ea93134574c2a22b87baad3de0bf8d64d42")
+    version("1.9.1", tag="v1.9.1", commit="dfbd030854359207cb3040b864614affeace11ce")
+    version("1.9.0", tag="v1.9.0", commit="d69c22dd61a2f006dcfe1e3ea8468a3ecaf931aa")
+    version("1.8.2", tag="v1.8.2", commit="e0495a7aa104471d95dc85a1b8f6473fbcc427a8")
+    version("1.8.1", tag="v1.8.1", commit="56b43f4fec1f76953f15a627694d4bba34588969")
+    version("1.8.0", tag="v1.8.0", commit="37c1f4a7fef115d719104e871d0cf39434aa9d56")
+    version("1.7.1", tag="v1.7.1", commit="57bffc3a8e4fee0cce31e1ff1f662ccf7b16db57")
+    version("1.7.0", tag="v1.7.0", commit="e85d494707b835c12165976b8442af54b9afcb26")
+    version("1.6.0", tag="v1.6.0", commit="b31f58de6fa8bbda5353b3c77d9be4914399724d")
+    version("1.5.1", tag="v1.5.1", commit="3c31d73c875d9a4a6ea8a843b9a0d1b19fbe36f3")
+    version("1.5.0", tag="v1.5.0", commit="4ff3872a2099993bf7e8c588f7182f3df777205b")
+    version("1.4.1", tag="v1.4.1", commit="74044638f755cd8667bedc73da4dbda4aa64c948")
+
+    depends_on("c", type="build")
+    depends_on("cxx", type="build")
+
+    is_darwin = sys.platform == "darwin"
+
+    # All options are defined in CMakeLists.txt.
+    # Some are listed in setup.py, but not all.
+    variant("debug", default=False, description="Build with debugging support")
+    variant("caffe2", default=False, description="Build Caffe2", when="@1.7:")
+    variant("test", default=False, description="Build C++ test binaries")
+    variant("cuda", default=not is_darwin, description="Use CUDA")
+    variant("rocm", default=False, description="Use ROCm")
+    variant("cudnn", default=not is_darwin, description="Use cuDNN", when="+cuda")
+    variant("fbgemm", default=True, description="Use FBGEMM (quantized 8-bit server operators)")
+    variant("kineto", default=True, description="Use Kineto profiling library", when="@1.8:")
+    variant("magma", default=not is_darwin, description="Use MAGMA", when="+cuda")
+    variant("metal", default=is_darwin, description="Use Metal for Caffe2 iOS build")
+    variant(
+        "mps",
+        default=is_darwin and macos_version() >= Version("12.3"),
+        description="Use MPS for macOS build (requires full Xcode suite)",
+        when="@1.12: platform=darwin",
+    )
+    variant("nccl", default=True, description="Use NCCL", when="+cuda platform=linux")
+    variant("nccl", default=True, description="Use NCCL", when="+rocm platform=linux")
+    # Requires AVX2: https://discuss.pytorch.org/t/107518
+    variant("nnpack", default=True, description="Use NNPACK", when="target=x86_64_v3:")
+    variant("numa", default=True, description="Use NUMA", when="platform=linux")
+    variant("numpy", default=True, description="Use NumPy")
+    variant("openmp", default=True, description="Use OpenMP for parallel code")
+    variant("qnnpack", default=True, description="Use QNNPACK (quantized 8-bit operators)")
+    variant("valgrind", default=True, description="Use Valgrind", when="@1.8: platform=linux")
+    variant("xnnpack", default=True, description="Use XNNPACK", when="@1.5:")
+    variant("mkldnn", default=True, description="Use MKLDNN")
+    variant("distributed", default=True, description="Use distributed")
+    variant("mpi", default=True, description="Use MPI for Caffe2", when="+distributed")
+    variant("ucc", default=False, description="Use UCC", when="@1.13: +distributed")
+    variant("gloo", default=True, description="Use Gloo", when="+distributed")
+    variant("tensorpipe", default=True, description="Use TensorPipe", when="@1.6: +distributed")
+    variant("onnx_ml", default=True, description="Enable traditional ONNX ML API", when="@1.5:")
+    variant(
+        "breakpad",
+        default=True,
+        description="Enable breakpad crash dump library",
+        when="@1.10:1.11",
+    )
+    # py-torch has strict dependencies on old protobuf/py-protobuf versions that
+    # cause problems with other packages that require newer versions of protobuf
+    # and py-protobuf --> provide an option to use the internal/vendored protobuf.
+    variant("custom-protobuf", default=False, description="Use vendored protobuf")
+
+    conflicts("+cuda+rocm")
+    conflicts("+tensorpipe", when="+rocm ^hip@:5.1", msg="TensorPipe not supported until ROCm 5.2")
+    conflicts("+breakpad", when="target=ppc64:")
+    conflicts("+breakpad", when="target=ppc64le:")
+
+    # https://github.com/pytorch/pytorch/issues/77811
+    conflicts("+qnnpack", when="platform=darwin target=aarch64:")
+
+    # https://github.com/pytorch/pytorch/issues/97397
+    conflicts(
+        "~tensorpipe",
+        when="@1.8: +distributed",
+        msg="TensorPipe must be enabled with +distributed",
+    )
+
+    # https://github.com/pytorch/pytorch/issues/100991
+    conflicts("%apple-clang@14:", when="@:1")
+
+    conflicts(
+        "cuda_arch=none",
+        when="+cuda",
+        msg="Must specify CUDA compute capabilities of your GPU, see "
+        "https://developer.nvidia.com/cuda-gpus",
+    )
+
+    # Required dependencies
+    # Based on PyPI wheel availability
+    with default_args(type=("build", "link", "run")):
+        depends_on("python@3.9:3.13", when="@2.5:")
+        depends_on("python@3.8:3.12", when="@2.2:2.4")
+        depends_on("python@3.8:3.11", when="@2.0:2.1")
+        depends_on("python@:3.10", when="@1.11:1")
+        depends_on("python@:3.9", when="@1.7.1:1.10")
+        depends_on("python@:3.8", when="@1.4:1.7.0")
+
+    # CMakelists.txt
+    with default_args(type="build"):
+        depends_on("cmake@3.18:", when="@2:")
+        depends_on("cmake@3.13:", when="@1.11:")
+        depends_on("cmake@3.10:", when="@1.10:")
+        depends_on("cmake@3.5:")
+        depends_on("ninja@1.5:")
+
+    with default_args(type=("build", "run")):
+        # setup.py
+        depends_on("py-filelock", when="@2:")
+        depends_on("py-typing-extensions@4.8:", when="@2.2:")
+        depends_on("py-typing-extensions@3.6.2.1:", when="@1.7:")
+        depends_on("py-sympy", when="@2:")
+        # begin EBRAINS (added): fix sympy version for py-torch@2.5: (from setup.py)
+        depends_on("py-sympy@1.13.1", when="@2.5:^python@3.9:")
+        # end EBRAINS
+        depends_on("py-networkx", when="@2:")
+        depends_on("py-jinja2", when="@2:")
+        depends_on("py-fsspec", when="@2.1:")
+
+        # pyproject.toml
+        depends_on("py-setuptools")
+        depends_on("py-astunparse", when="@1.13:")
+        depends_on("py-numpy@1.16.6:")
+        # https://github.com/pytorch/pytorch/issues/107302
+        depends_on("py-numpy@:1", when="@:2.2")
+        depends_on("py-pyyaml")
+        depends_on("py-requests", when="@1.13:")
+
+    # Undocumented dependencies
+    depends_on("py-tqdm", type="run")
+    depends_on("blas")
+    depends_on("lapack")
+
+    # Third party dependencies
+    depends_on("fp16@2020-05-14", when="@1.6:")
+    depends_on("fxdiv@2020-04-17", when="@1.6:")
+    # https://github.com/pytorch/pytorch/issues/60332
+    # depends_on("xnnpack@2024-02-29", when="@2.3:+xnnpack")
+    # depends_on("xnnpack@2022-12-21", when="@2.0:2.2+xnnpack")
+    # depends_on("xnnpack@2022-02-16", when="@1.12:1+xnnpack")
+    # depends_on("xnnpack@2021-06-21", when="@1.10:1.11+xnnpack")
+    # depends_on("xnnpack@2021-02-22", when="@1.8:1.9+xnnpack")
+    # depends_on("xnnpack@2020-03-23", when="@1.6:1.7+xnnpack")
+    depends_on("benchmark", when="@1.6:+test")
+    depends_on("cpuinfo@2024-09-06", when="@2.5.1:")
+    depends_on("cpuinfo@2024-08-30", when="@2.5.0")
+    depends_on("cpuinfo@2023-11-04", when="@2.3:2.4")
+    depends_on("cpuinfo@2023-01-13", when="@2.1:2.2")
+    depends_on("cpuinfo@2022-08-19", when="@1.13:2.0")
+    depends_on("cpuinfo@2020-12-17", when="@1.8:1.12")
+    depends_on("cpuinfo@2020-06-11", when="@1.6:1.7")
+    depends_on("eigen")
+    depends_on("gloo@2023-12-03", when="@2.3:+gloo")
+    depends_on("gloo@2023-05-19", when="@2.1:2.2+gloo")
+    depends_on("gloo@2023-01-17", when="@2.0+gloo")
+    depends_on("gloo@2022-05-18", when="@1.13:1+gloo")
+    depends_on("gloo@2021-05-21", when="@1.10:1.12+gloo")
+    depends_on("gloo@2021-05-04", when="@1.9+gloo")
+    depends_on("gloo@2020-09-18", when="@1.7:1.8+gloo")
+    depends_on("gloo@2020-03-17", when="@1.6+gloo")
+    depends_on("gloo+cuda", when="@1.6:+gloo+cuda")
+    depends_on("gloo+libuv", when="@1.6: platform=darwin")
+    depends_on("nccl", when="+nccl+cuda")
+    # https://github.com/pytorch/pytorch/issues/60331
+    # depends_on("onnx@1.16.0", when="@2.3:+onnx_ml")
+    # depends_on("onnx@1.15.0", when="@2.2+onnx_ml")
+    # depends_on("onnx@1.14.1", when="@2.1+onnx_ml")
+    # depends_on("onnx@1.13.1", when="@2.0+onnx_ml")
+    # depends_on("onnx@1.12.0", when="@1.13:1+onnx_ml")
+    # depends_on("onnx@1.11.0", when="@1.12+onnx_ml")
+    # depends_on("onnx@1.10.1_2021-10-08", when="@1.11+onnx_ml")
+    # depends_on("onnx@1.10.1", when="@1.10+onnx_ml")
+    # depends_on("onnx@1.8.0_2020-11-03", when="@1.8:1.9+onnx_ml")
+    # depends_on("onnx@1.7.0_2020-05-31", when="@1.6:1.7+onnx_ml")
+    with when("~custom-protobuf"):
+        depends_on("protobuf@3.13.0", when="@1.10:")
+        depends_on("protobuf@3.11.4", when="@1.6:1.9")
+        depends_on("protobuf@3.6.1", when="@1.1:1.5")
+        depends_on("protobuf@3.5.0", when="@1.0")
+        with default_args(type=("build", "run")):
+            depends_on("py-protobuf@3.13", when="@1.10:")
+            depends_on("py-protobuf@3.11", when="@1.6:1.9")
+            depends_on("py-protobuf@3.6", when="@1.1:1.5")
+            depends_on("py-protobuf@3.5", when="@1.0")
+    depends_on("psimd@2020-05-17", when="@1.6:")
+    depends_on("pthreadpool@2023-08-29", when="@2.2:")
+    depends_on("pthreadpool@2021-04-13", when="@1.9:2.1")
+    depends_on("pthreadpool@2020-10-05", when="@1.8")
+    depends_on("pthreadpool@2020-06-15", when="@1.6:1.7")
+    with default_args(type=("build", "link", "run")):
+        depends_on("py-pybind11@2.13.5:", when="@2.5:")
+        depends_on("py-pybind11@2.12.0:", when="@2.3:2.4")
+        depends_on("py-pybind11@2.11.0:", when="@2.1:2.2")
+        depends_on("py-pybind11@2.10.1:", when="@2.0")
+        depends_on("py-pybind11@2.10.0:", when="@1.13:1")
+        depends_on("py-pybind11@2.6.2:", when="@1.8:1.12")
+        depends_on("py-pybind11@2.3.0:", when="@:1.7")
+    depends_on("sleef@3.6.0_2024-03-20", when="@2.4:")
+    depends_on("sleef@3.5.1_2020-12-22", when="@1.8:2.3")
+    depends_on("sleef@3.4.0_2019-07-30", when="@1.6:1.7")
+
+    # Optional dependencies
+    with default_args(type=("build", "link", "run")):
+        # cmake/public/cuda.cmake
+        depends_on("cuda@11:", when="@2.4:+cuda")
+        # https://github.com/pytorch/pytorch/issues/122169
+        depends_on("cuda@11:12.3", when="@2.0:2.3+cuda")
+        depends_on("cuda@10.2:12.3", when="@1.11:1+cuda")
+        # https://discuss.pytorch.org/t/compiling-1-10-1-from-source-with-gcc-11-and-cuda-11-5/140971
+        depends_on("cuda@10.2:11.4", when="@1.10+cuda")
+        depends_on("cuda@9.2:11.4", when="@1.6:1.9+cuda")
+        depends_on("cuda@9:11.4", when="@:1.5+cuda")
+    # https://github.com/pytorch/pytorch#prerequisites
+    # https://github.com/pytorch/pytorch/issues/119400
+    depends_on("cudnn@8.5:9.0", when="@2.3:+cudnn")
+    depends_on("cudnn@7:8", when="@1.6:2.2+cudnn")
+    depends_on("cudnn@7", when="@:1.5+cudnn")
+    depends_on("magma+cuda", when="+magma+cuda")
+    depends_on("magma+rocm", when="+magma+rocm")
+    depends_on("numactl", when="+numa")
+    depends_on("llvm-openmp", when="%apple-clang +openmp")
+    depends_on("valgrind", when="+valgrind")
+    with when("+rocm"):
+        depends_on("hsa-rocr-dev")
+        depends_on("hip")
+        depends_on("rccl", when="+nccl")
+        depends_on("rocprim")
+        depends_on("hipcub")
+        depends_on("rocthrust")
+        depends_on("roctracer-dev")
+        depends_on("rocrand")
+        depends_on("hipsparse")
+        depends_on("hipfft")
+        depends_on("rocfft")
+        depends_on("rocblas")
+        depends_on("miopen-hip")
+        depends_on("rocminfo")
+    depends_on("mpi", when="+mpi")
+    depends_on("ucc", when="+ucc")
+    depends_on("ucx", when="+ucc")
+    depends_on("mkl", when="+mkldnn")
+
+    # Test dependencies
+    with default_args(type="test"):
+        depends_on("py-hypothesis")
+        depends_on("py-six")
+        depends_on("py-psutil")
+
+    # Historical dependencies
+    with default_args(type=("build", "run")):
+        depends_on("mkl@2021.1.1:2021.4.0", when="@2.3 platform=windows")
+        depends_on("py-cffi", when="@:1")
+        depends_on("py-future", when="@1.5:1")
+        depends_on("py-six", when="@1.13:1")
+
+    conflicts("%gcc@:9.3", when="@2.2:", msg="C++17 support required")
+
+    # https://github.com/pytorch/pytorch/issues/90448
+    patch(
+        "https://github.com/pytorch/pytorch/pull/97270.patch?full_index=1",
+        sha256="beb3fb57746cf8443f5caa6e08b2f8f4d4822c1e11e0c912134bd166c6a0ade7",
+        when="@1.10:2.0",
+    )
+
+    # Fix BLAS being overridden by MKL
+    # https://github.com/pytorch/pytorch/issues/60328
+    patch(
+        "https://github.com/pytorch/pytorch/pull/59220.patch?full_index=1",
+        sha256="6d5717267f901e8ee493dfacd08734d9bcc48ad29a76ca9ef702368e96bee675",
+        when="@:1.11",
+    )
+
+    # Fixes build on older systems with glibc <2.12
+    patch(
+        "https://github.com/pytorch/pytorch/pull/55063.patch?full_index=1",
+        sha256="2229bcbf20fbe88aa9f7318f89c126ec7f527875ffe689a763c78abfa127a65c",
+        when="@:1.8.1",
+    )
+
+    # https://github.com/pytorch/pytorch/issues/70297
+    patch(
+        "https://github.com/google/breakpad/commit/605c51ed96ad44b34c457bbca320e74e194c317e.patch?full_index=1",
+        sha256="694d83db3a2147d543357f22ba5c8d5683d0ed43e693d42bca8f24ec50080f98",
+        when="+breakpad",
+        working_dir="third_party/breakpad",
+    )
+
+    # Fixes CMake configuration error when XNNPACK is disabled
+    # https://github.com/pytorch/pytorch/pull/35607
+    # https://github.com/pytorch/pytorch/pull/37865
+    patch("xnnpack.patch", when="@1.5")
+
+    # Fixes build error when ROCm is enabled for pytorch-1.5 release
+    patch("rocm.patch", when="@1.5+rocm")
+
+    # Fixes compilation with Clang 9.0.0 and Apple Clang 11.0.3
+    # https://github.com/pytorch/pytorch/pull/37086
+    patch(
+        "https://github.com/pytorch/pytorch/commit/e921cd222a8fbeabf5a3e74e83e0d8dfb01aa8b5.patch?full_index=1",
+        sha256="0f3ad037a95af9d34b1d085050c1e7771fd00f0b89e5b3a276097b7c9f4fabf8",
+        when="@:1.5",
+    )
+
+    # Fixes 'FindOpenMP.cmake'
+    # to detect openmp settings used by Fujitsu compiler.
+    patch("detect_omp_of_fujitsu_compiler.patch", when="%fj")
+
+    # Fixes to build with fujitsu-ssl2
+    patch("fj-ssl2_1.11.patch", when="@1.11:^fujitsu-ssl2")
+    patch("fj-ssl2_1.10.patch", when="@1.10^fujitsu-ssl2")
+    patch("fj-ssl2_1.9.patch", when="@1.9^fujitsu-ssl2")
+    patch("fj-ssl2_1.8.patch", when="@1.8^fujitsu-ssl2")
+    patch("fj-ssl2_1.6-1.7.patch", when="@1.6:1.7^fujitsu-ssl2")
+    patch("fj-ssl2_1.3-1.5.patch", when="@:1.5^fujitsu-ssl2")
+
+    # Fix compilation of +distributed~tensorpipe
+    # https://github.com/pytorch/pytorch/issues/68002
+    patch(
+        "https://github.com/pytorch/pytorch/commit/c075f0f633fa0136e68f0a455b5b74d7b500865c.patch?full_index=1",
+        sha256="41271e494a3a60a65a8dd45ac053d1a6e4e4d5b42c2dac589ac67524f61ac41e",
+        when="@1.10.0+distributed~tensorpipe",
+    )
+
+    # Use patches from IBM's Open CE to enable building on Power systems
+    # 01xx patches are specific to open-ce, we only include 03xx patches used in meta.yaml
+    # https://github.com/open-ce/pytorch-feedstock
+    patch(
+        "https://github.com/open-ce/pytorch-feedstock/raw/open-ce-v1.7.4/pytorch-1.10/recipe/0302-cpp-extension.patch",
+        sha256="ecb3973fa7d0f4c8f8ae40433f3ca5622d730a7b16f6cb63325d1e95baff8aa2",
+        when="@1.10:1.11 arch=ppc64le:",
+    )
+    patch(
+        "https://github.com/open-ce/pytorch-feedstock/raw/open-ce-v1.7.4/pytorch-1.10/recipe/0311-PR66085-Remove-unused-dump-method-from-VSX-vec256-methods.patch",
+        sha256="f05db59f3def4c4215db7142d81029c73fe330c660492159b66d65ca5001f4d1",
+        when="@1.10 arch=ppc64le:",
+    )
+    patch(
+        "https://github.com/open-ce/pytorch-feedstock/raw/open-ce-v1.7.4/pytorch-1.10/recipe/0312-PR67331-Dummpy-VSX-bfloat16-implementation.patch",
+        sha256="860b64afa85f5e6647ebc3c91d5a0bb258784770900c9302c3599c98d5cff1ee",
+        when="@1.10 arch=ppc64le:",
+    )
+    patch(
+        "https://github.com/open-ce/pytorch-feedstock/raw/open-ce-v1.7.4/pytorch-1.10/recipe/0313-add-missing-vsx-dispatch.patch",
+        sha256="7393c2bc0b6d41ecc813c829a1e517bee864686652e91f174cb7bcdfb10ba451",
+        when="@1.10 arch=ppc64le:",
+    )
+    patch(
+        "https://github.com/open-ce/pytorch-feedstock/raw/open-ce-v1.7.4/pytorch-1.10/recipe/0314-fix-nullpointer-error.patch",
+        sha256="b9cff8966f316f58514c66a403b7a6786be3cdb252f1380a6b91c722686a4097",
+        when="@1.10 arch=ppc64le:",
+    )
+    patch(
+        "https://github.com/open-ce/pytorch-feedstock/raw/open-ce-v1.7.4/pytorch-1.12/recipe/0302-cpp-extension.patch",
+        sha256="2fac519cca8997f074c263505657ff867e7ba2d6637fc8bda99c70a99be0442a",
+        when="@1.12 arch=ppc64le:",
+    )
+    patch(
+        "https://github.com/open-ce/pytorch-feedstock/raw/open-ce-v1.8.0/pytorch-1.13/recipe/0302-cpp-extension.patch",
+        sha256="a54db63640b90e5833cc1099c0935572f5297d2d8625f62f01ac1fda79ed4569",
+        when="@1.13 arch=ppc64le:",
+    )
+    patch(
+        "https://github.com/open-ce/pytorch-feedstock/raw/open-ce-v1.9.0/pytorch-2.0/recipe/0309-fallback-to-cpu_kernel-with-VSX.patch",
+        sha256="27f41c8d6cb61e69e761be62f03dc1ce023cbca34926e3ba559996821a7ce726",
+        when="@2.0 arch=ppc64le:",
+    )
+    patch(
+        "https://github.com/open-ce/pytorch-feedstock/raw/open-ce-v1.9.0/pytorch-2.0/recipe/0310-PR100149.patch",
+        sha256="1adbd38a9cc1611f1caaa325614695f4349d9ffd236332e0d8f0de5a3880f4dd",
+        when="@2.0 arch=ppc64le:",
+    )
+    patch(
+        "https://github.com/open-ce/pytorch-feedstock/raw/open-ce-v1.10.0/pytorch-2.0/recipe/0311-PR104956.patch",
+        sha256="be27c906924a21be198a3ea6c459739a1daa8b8b89045af339dafa4cd6f90d6c",
+        when="@2.0 arch=ppc64le:",
+    )
+    conflicts("arch=ppc64le:", when="@:1.9")
+
+    # Cherry-pick a patch to allow earlier versions of PyTorch to work with CUDA 11.4
+    patch(
+        "https://github.com/pytorch/pytorch/commit/c74c0c571880df886474be297c556562e95c00e0.patch?full_index=1",
+        sha256="8ff7d285e52e4718bad1ca01ceb3bb6471d7828329036bb94222717fcaa237da",
+        when="@:1.9.1 ^cuda@11.4.100:",
+    )
+
+    # PyTorch does not build with GCC 12 (fixed in 2.0)
+    # See: https://github.com/pytorch/pytorch/issues/77614
+    patch(
+        "https://github.com/facebookincubator/gloo/commit/4a5e339b764261d20fc409071dc7a8b8989aa195.patch?full_index=1",
+        sha256="dc8b3a9bea4693f32d6850ea2ce6ce75e1778538bfba464b50efca92bac425e3",
+        when="@:1 %gcc@12:",
+        working_dir="third_party/gloo",
+    )
+
+    # PyTorch does not build on Linux >=6.0.3 (fixed in master)
+    # See: https://github.com/facebookincubator/gloo/issues/345
+    patch(
+        "https://github.com/facebookincubator/gloo/commit/10909297fedab0a680799211a299203e53515032.patch?full_index=1",
+        sha256="8e6e9a44e0533ba4303a95a651b1934e5d73632cab08cc7d5a9435e1e64aa424",
+        when="@:1",
+        working_dir="third_party/gloo",
+    )
+
+    # Some missing includes
+    # See: https://github.com/pytorch/pytorch/pull/100036
+    patch(
+        "https://patch-diff.githubusercontent.com/raw/pytorch/pytorch/pull/100036.patch?full_index=1",
+        sha256="65060b54c31196b26dcff29bbb178fd17d5677e8481a2a06002c0ca4dd37b3d0",
+        when="@2.0.0:2.0.1",
+    )
+    # See: https://github.com/pytorch/pytorch/pull/100049
+    patch(
+        "https://patch-diff.githubusercontent.com/raw/pytorch/pytorch/pull/100049.patch?full_index=1",
+        sha256="673056141c0ea6ff4411f65a26f1a9d7a7c49ad8fe034a01ef0d56ba8a7a9386",
+        when="@2.0.0:2.0.1",
+    )
+
+    # Use correct OpenBLAS include path under prefix
+    patch(
+        "https://patch-diff.githubusercontent.com/raw/pytorch/pytorch/pull/110063.patch?full_index=1",
+        sha256="23fb4009f7337051fc5303927ff977186a5af960245e7212895406477d8b2f66",
+        when="@:2.1",
+    )
+
+    patch(
+        "https://github.com/pytorch/FBGEMM/commit/da01a59556fec9776733bf20aea8fe8fb29cdd3d.patch?full_index=1",
+        sha256="97d8bd43f8cd8bb203dab3480d609c08499224acaca9915f2bdeb23c62350fb1",
+        when="@2.0.1 +fbgemm",
+        working_dir="third_party/fbgemm",
+    )
+
+    # begin EBRAINS (added): see https://github.com/pytorch/pytorch/issues/129304
+    patch(
+        "https://github.com/pytorch/pytorch/commit/9174d14551c4c6f594bd1532ab00fb7158b1bbfa.patch?full_index=1",
+        sha256="25204236888f25ea74c081787a01deae1a6fa66ecd77ecbe280e1ce8af6b8116",
+        when="@2.4",
+    )
+    # end EBRAINS
+
+    @when("@1.5.0:")
+    def patch(self):
+        # https://github.com/pytorch/pytorch/issues/52208
+        filter_file(
+            "torch_global_deps PROPERTIES LINKER_LANGUAGE C",
+            "torch_global_deps PROPERTIES LINKER_LANGUAGE CXX",
+            "caffe2/CMakeLists.txt",
+        )
+
+    def torch_cuda_arch_list(self, env):
+        if "+cuda" in self.spec:
+            torch_cuda_arch = CudaPackage.compute_capabilities(
+                self.spec.variants["cuda_arch"].value
+            )
+            env.set("TORCH_CUDA_ARCH_LIST", ";".join(torch_cuda_arch))
+
+    def setup_build_environment(self, env):
+        """Set environment variables used to control the build.
+
+        PyTorch's ``setup.py`` is a thin wrapper around ``cmake``.
+        In ``tools/setup_helpers/cmake.py``, you can see that all
+        environment variables that start with ``BUILD_``, ``USE_``,
+        or ``CMAKE_``, plus a few more explicitly specified variable
+        names, are passed directly to the ``cmake`` call. Therefore,
+        most flags defined in ``CMakeLists.txt`` can be specified as
+        environment variables.
+        """
+
+        def enable_or_disable(variant, keyword="USE", var=None):
+            """Set environment variable to enable or disable support for a
+            particular variant.
+
+            Parameters:
+                variant (str): the variant to check
+                keyword (str): the prefix to use for enabling/disabling
+                var (str): CMake variable to set. Defaults to variant.upper()
+            """
+            if var is None:
+                var = variant.upper()
+
+            if "+" + variant in self.spec:
+                env.set(keyword + "_" + var, "ON")
+            elif "~" + variant in self.spec:
+                env.set(keyword + "_" + var, "OFF")
+
+        # Build in parallel to speed up build times
+        env.set("MAX_JOBS", make_jobs)
+
+        # Spack logs have trouble handling colored output
+        env.set("COLORIZE_OUTPUT", "OFF")
+
+        enable_or_disable("test", keyword="BUILD")
+        enable_or_disable("caffe2", keyword="BUILD")
+
+        enable_or_disable("cuda")
+        if "+cuda" in self.spec:
+            env.set("CUDA_TOOLKIT_ROOT_DIR", self.spec["cuda"].prefix)  # Linux/macOS
+            env.set("CUDA_HOME", self.spec["cuda"].prefix)  # Linux/macOS
+            env.set("CUDA_PATH", self.spec["cuda"].prefix)  # Windows
+            self.torch_cuda_arch_list(env)
+
+            if self.spec.satisfies("%clang"):
+                for flag in self.spec.compiler_flags["cxxflags"]:
+                    if "gcc-toolchain" in flag:
+                        env.set("CMAKE_CUDA_FLAGS", "=-Xcompiler={0}".format(flag))
+
+        enable_or_disable("rocm")
+        if "+rocm" in self.spec:
+            env.set("PYTORCH_ROCM_ARCH", ";".join(self.spec.variants["amdgpu_target"].value))
+            env.set("HSA_PATH", self.spec["hsa-rocr-dev"].prefix)
+            env.set("ROCBLAS_PATH", self.spec["rocblas"].prefix)
+            env.set("ROCFFT_PATH", self.spec["rocfft"].prefix)
+            env.set("HIPFFT_PATH", self.spec["hipfft"].prefix)
+            env.set("HIPSPARSE_PATH", self.spec["hipsparse"].prefix)
+            env.set("HIP_PATH", self.spec["hip"].prefix)
+            env.set("HIPRAND_PATH", self.spec["rocrand"].prefix)
+            env.set("ROCRAND_PATH", self.spec["rocrand"].prefix)
+            env.set("MIOPEN_PATH", self.spec["miopen-hip"].prefix)
+            if "+nccl" in self.spec:
+                env.set("RCCL_PATH", self.spec["rccl"].prefix)
+            env.set("ROCPRIM_PATH", self.spec["rocprim"].prefix)
+            env.set("HIPCUB_PATH", self.spec["hipcub"].prefix)
+            env.set("ROCTHRUST_PATH", self.spec["rocthrust"].prefix)
+            env.set("ROCTRACER_PATH", self.spec["roctracer-dev"].prefix)
+            if self.spec.satisfies("^hip@5.2.0:"):
+                env.set("CMAKE_MODULE_PATH", self.spec["hip"].prefix.lib.cmake.hip)
+
+        enable_or_disable("cudnn")
+        if "+cudnn" in self.spec:
+            # cmake/Modules_CUDA_fix/FindCUDNN.cmake
+            env.set("CUDNN_INCLUDE_DIR", self.spec["cudnn"].prefix.include)
+            env.set("CUDNN_LIBRARY", self.spec["cudnn"].libs[0])
+
+        # Flash attention has very high memory requirements that may cause the build to fail
+        # https://github.com/pytorch/pytorch/issues/111526
+        # https://github.com/pytorch/pytorch/issues/124018
+        env.set("USE_FLASH_ATTENTION", "OFF")
+
+        enable_or_disable("fbgemm")
+        enable_or_disable("kineto")
+        enable_or_disable("magma")
+        enable_or_disable("metal")
+        enable_or_disable("mps")
+        enable_or_disable("breakpad")
+
+        enable_or_disable("nccl")
+        if "+cuda+nccl" in self.spec:
+            env.set("NCCL_LIB_DIR", self.spec["nccl"].libs.directories[0])
+            env.set("NCCL_INCLUDE_DIR", self.spec["nccl"].prefix.include)
+
+        # cmake/External/nnpack.cmake
+        enable_or_disable("nnpack")
+
+        enable_or_disable("numa")
+        if "+numa" in self.spec:
+            # cmake/Modules/FindNuma.cmake
+            env.set("NUMA_ROOT_DIR", self.spec["numactl"].prefix)
+
+        # cmake/Modules/FindNumPy.cmake
+        enable_or_disable("numpy")
+        # cmake/Modules/FindOpenMP.cmake
+        enable_or_disable("openmp")
+        enable_or_disable("qnnpack")
+        enable_or_disable("qnnpack", var="PYTORCH_QNNPACK")
+        enable_or_disable("valgrind")
+        enable_or_disable("xnnpack")
+        enable_or_disable("mkldnn")
+        enable_or_disable("distributed")
+        enable_or_disable("mpi")
+        enable_or_disable("ucc")
+        # cmake/Modules/FindGloo.cmake
+        enable_or_disable("gloo")
+        enable_or_disable("tensorpipe")
+
+        if "+debug" in self.spec:
+            env.set("DEBUG", "ON")
+        else:
+            env.set("DEBUG", "OFF")
+
+        if "+onnx_ml" in self.spec:
+            env.set("ONNX_ML", "ON")
+        elif "~onnx_ml" in self.spec:
+            env.set("ONNX_ML", "OFF")
+
+        if not self.spec.satisfies("@main"):
+            env.set("PYTORCH_BUILD_VERSION", self.version)
+            env.set("PYTORCH_BUILD_NUMBER", 0)
+
+        # BLAS to be used by Caffe2
+        # Options defined in cmake/Dependencies.cmake and cmake/Modules/FindBLAS.cmake
+        if self.spec["blas"].name == "atlas":
+            env.set("BLAS", "ATLAS")
+            env.set("WITH_BLAS", "atlas")
+            env.set("Atlas_ROOT_DIR", self.spec["atlas"].prefix)
+        elif self.spec["blas"].name in ["blis", "amdblis"]:
+            env.set("BLAS", "BLIS")
+            env.set("WITH_BLAS", "blis")
+            env.set("BLIS_HOME", self.spec["blas"].prefix)
+        elif self.spec["blas"].name == "eigen":
+            env.set("BLAS", "Eigen")
+        elif self.spec["lapack"].name in ["libflame", "amdlibflame"]:
+            env.set("BLAS", "FLAME")
+            env.set("WITH_BLAS", "FLAME")
+        elif self.spec["blas"].name in ["intel-mkl", "intel-parallel-studio", "intel-oneapi-mkl"]:
+            env.set("BLAS", "MKL")
+            env.set("WITH_BLAS", "mkl")
+            # help find MKL
+            if self.spec["mkl"].name == "intel-oneapi-mkl":
+                env.set("INTEL_MKL_DIR", self.spec["mkl"].prefix.mkl.latest)
+            else:
+                env.set("INTEL_MKL_DIR", self.spec["mkl"].prefix.mkl)
+        elif self.spec["blas"].name == "openblas":
+            env.set("BLAS", "OpenBLAS")
+            env.set("WITH_BLAS", "open")
+            env.set("OpenBLAS_HOME", self.spec["openblas"].prefix)
+        elif self.spec["blas"].name == "veclibfort":
+            env.set("BLAS", "vecLib")
+            env.set("WITH_BLAS", "veclib")
+        elif self.spec["blas"].name == "fujitsu-ssl2":
+            env.set("BLAS", "SSL2")
+            env.set("WITH_BLAS", "ssl2")
+        else:
+            env.set("BLAS", "Generic")
+            env.set("WITH_BLAS", "generic")
+
+        # Don't use vendored third-party libraries when possible
+        # env.set("USE_SYSTEM_LIBS", "ON")
+        env.set("USE_SYSTEM_BENCHMARK", "ON")
+        env.set("USE_SYSTEM_CPUINFO", "ON")
+        env.set("USE_SYSTEM_EIGEN_INSTALL", "ON")
+        env.set("USE_SYSTEM_FP16", "ON")
+        env.set("USE_SYSTEM_FXDIV", "ON")
+        env.set("USE_SYSTEM_GLOO", "ON")
+        env.set("USE_SYSTEM_NCCL", "ON")
+        # https://github.com/pytorch/pytorch/issues/60331
+        # env.set("USE_SYSTEM_ONNX", "ON")
+        env.set("USE_SYSTEM_PSIMD", "ON")
+        env.set("USE_SYSTEM_PTHREADPOOL", "ON")
+        env.set("USE_SYSTEM_PYBIND11", "ON")
+        env.set("USE_SYSTEM_SLEEF", "ON")
+        env.set("USE_SYSTEM_UCC", "ON")
+        # https://github.com/pytorch/pytorch/issues/60332
+        # env.set("USE_SYSTEM_XNNPACK", "ON")
+
+        if self.spec.satisfies("+custom-protobuf"):
+            env.set("BUILD_CUSTOM_PROTOBUF", "ON")
+        else:
+            env.set("BUILD_CUSTOM_PROTOBUF", "OFF")
+
+    def setup_run_environment(self, env):
+        self.torch_cuda_arch_list(env)
+
+    @run_before("install")
+    def build_amd(self):
+        if "+rocm" in self.spec:
+            python(os.path.join("tools", "amd_build", "build_amd.py"))
+
+    @run_after("install")
+    @on_package_attributes(run_tests=True)
+    def install_test(self):
+        with working_dir("test"):
+            python("run_test.py")
+
+    @property
+    def cmake_prefix_paths(self):
+        cmake_prefix_paths = [join_path(python_platlib, "torch", "share", "cmake")]
+        return cmake_prefix_paths
diff --git a/packages/py-torch/rocm.patch b/packages/py-torch/rocm.patch
new file mode 100644
index 0000000000000000000000000000000000000000..b50cc7e1598a23f41e1e1a73e6672e6a4d132b6a
--- /dev/null
+++ b/packages/py-torch/rocm.patch
@@ -0,0 +1,98 @@
+diff --git a/aten/src/ATen/cuda/nvrtc_stub/ATenNVRTC.h b/aten/src/ATen/cuda/nvrtc_stub/ATenNVRTC.h
+index 9cd678dfb4cc7..4630465115c7c 100644
+--- a/aten/src/ATen/cuda/nvrtc_stub/ATenNVRTC.h
++++ b/aten/src/ATen/cuda/nvrtc_stub/ATenNVRTC.h
+@@ -67,6 +67,14 @@ namespace at { namespace cuda {
+ //
+ // HIP doesn't have
+ //   cuGetErrorString  (maps to non-functional hipGetErrorString___)
++//
++// HIP from ROCm 3.5 on renamed hipOccupancyMaxActiveBlocksPerMultiprocessor
++// to hipModuleOccupancyMaxActiveBlocksPerMultiprocessor.
++#if HIP_VERSION < 305
++#define HIPOCCUPANCYMAXACTIVEBLOCKSPERMULTIPROCESSOR hipOccupancyMaxActiveBlocksPerMultiprocessor
++#else
++#define HIPOCCUPANCYMAXACTIVEBLOCKSPERMULTIPROCESSOR cuOccupancyMaxActiveBlocksPerMultiprocessor
++#endif
+ 
+ #define AT_FORALL_NVRTC(_)                       \
+   _(nvrtcVersion)                                \
+@@ -76,7 +84,7 @@ namespace at { namespace cuda {
+   _(nvrtcGetPTX)                                 \
+   _(cuModuleLoadData)                            \
+   _(cuModuleGetFunction)                         \
+-  _(cuOccupancyMaxActiveBlocksPerMultiprocessor) \
++  _(HIPOCCUPANCYMAXACTIVEBLOCKSPERMULTIPROCESSOR)\
+   _(nvrtcGetErrorString)                         \
+   _(nvrtcGetProgramLogSize)                      \
+   _(nvrtcGetProgramLog)                          \
+diff --git a/aten/src/ATen/native/cuda/SoftMax.cu b/aten/src/ATen/native/cuda/SoftMax.cu
+index da1995123ecfc..f935eb4ef3d0e 100644
+--- a/aten/src/ATen/native/cuda/SoftMax.cu
++++ b/aten/src/ATen/native/cuda/SoftMax.cu
+@@ -127,8 +127,8 @@ void SpatialSoftMax_getLaunchSizes(
+   uint32_t block_threads = block.x * block.y;
+   smem_size = block.x == 1 ? 0 : block_threads * sizeof(accscalar_t);
+   int max_active_blocks;
+-#ifdef __HIP_PLATFORM_HCC__
+-  // XXX HIP function signature is not compatible yet.
++#if defined(__HIP_PLATFORM_HCC__) && HIP_VERSION < 305
++  // HIP function signature is not compatible yet.
+   uint32_t max_blocks;
+   cudaOccupancyMaxActiveBlocksPerMultiprocessor(&max_blocks,
+                                                 k, block_threads, smem_size);
+diff --git a/torch/csrc/jit/codegen/fuser/cuda/fused_kernel.cpp b/torch/csrc/jit/codegen/fuser/cuda/fused_kernel.cpp
+index 5586e49919727..27315ee475277 100644
+--- a/torch/csrc/jit/codegen/fuser/cuda/fused_kernel.cpp
++++ b/torch/csrc/jit/codegen/fuser/cuda/fused_kernel.cpp
+@@ -140,10 +140,10 @@ FusedKernelCUDA::FusedKernelCUDA(
+       nvrtc().cuModuleGetFunction(&function_, module_, name_.c_str()));
+ 
+   // Computes max blocks
+-#ifdef __HIP_PLATFORM_HCC__
+-  // XXX HIP function signature is not compatible yet
++#if defined(__HIP_PLATFORM_HCC__) && HIP_VERSION < 305
++  // HIP function signature is not compatible yet
+   uint32_t max_blocks;
+-  AT_CUDA_DRIVER_CHECK(nvrtc().cuOccupancyMaxActiveBlocksPerMultiprocessor(
++  AT_CUDA_DRIVER_CHECK(nvrtc().hipOccupancyMaxActiveBlocksPerMultiprocessor(
+       &max_blocks, function_, 128, 0));
+   maxBlocks_ = max_blocks;
+ #else
+diff --git a/torch/utils/hipify/cuda_to_hip_mappings.py b/torch/utils/hipify/cuda_to_hip_mappings.py
+index 7e21363cbe6af..26f269d92ae38 100644
+--- a/torch/utils/hipify/cuda_to_hip_mappings.py
++++ b/torch/utils/hipify/cuda_to_hip_mappings.py
+@@ -2890,7 +2890,7 @@
+         (
+             "cuOccupancyMaxActiveBlocksPerMultiprocessor",
+             (
+-                "hipOccupancyMaxActiveBlocksPerMultiprocessor",
++                "hipModuleOccupancyMaxActiveBlocksPerMultiprocessor",
+                 CONV_OCCUPANCY,
+                 API_DRIVER,
+             ),
+@@ -2898,7 +2898,7 @@
+         (
+             "cuOccupancyMaxActiveBlocksPerMultiprocessorWithFlags",
+             (
+-                "hipOccupancyMaxActiveBlocksPerMultiprocessorWithFlags",
++                "hipModuleOccupancyMaxActiveBlocksPerMultiprocessorWithFlags",
+                 CONV_OCCUPANCY,
+                 API_DRIVER,
+                 HIP_UNSUPPORTED,
+@@ -2906,12 +2906,12 @@
+         ),
+         (
+             "cuOccupancyMaxPotentialBlockSize",
+-            ("hipOccupancyMaxPotentialBlockSize", CONV_OCCUPANCY, API_DRIVER),
++            ("hipModuleOccupancyMaxPotentialBlockSize", CONV_OCCUPANCY, API_DRIVER),
+         ),
+         (
+             "cuOccupancyMaxPotentialBlockSizeWithFlags",
+             (
+-                "hipOccupancyMaxPotentialBlockSizeWithFlags",
++                "hipModuleOccupancyMaxPotentialBlockSizeWithFlags",
+                 CONV_OCCUPANCY,
+                 API_DRIVER,
+                 HIP_UNSUPPORTED,
diff --git a/packages/py-torch/xnnpack.patch b/packages/py-torch/xnnpack.patch
new file mode 100644
index 0000000000000000000000000000000000000000..154033081e7ff91867e9a043a93c46b888bfe8cb
--- /dev/null
+++ b/packages/py-torch/xnnpack.patch
@@ -0,0 +1,47 @@
+diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt
+index 8025a7de3c..0da37079d6 100644
+--- a/caffe2/CMakeLists.txt
++++ b/caffe2/CMakeLists.txt
+@@ -46,12 +46,19 @@ if (INTERN_BUILD_ATEN_OPS)
+   list(APPEND Caffe2_DEPENDENCY_INCLUDE ${ATen_THIRD_PARTY_INCLUDE})
+ endif()
+ 
++# {Q/X,etc} NPACK support is enabled by default, if none of these options
++# are selected, turn this flag ON to incidate the support is disabled
++set(NNPACK_AND_FAMILY_DISABLED OFF)
++if(NOT (USE_NNPACK OR USE_QNNPACK OR USE_PYTORCH_QNNPACK OR USE_XNNPACK))
++  set(NNPACK_AND_FAMILY_DISABLED ON)
++endif()
++
+ # ---[ Caffe2 build
+ # Note: the folders that are being commented out have not been properly
+ # addressed yet.
+ 
+ # For pthreadpool_new_if_impl. TODO: Remove when threadpools are unitied.
+-if (NOT MSVC)
++if (NOT MSVC AND NOT NNPACK_AND_FAMILY_DISABLED)
+   IF(NOT TARGET fxdiv)
+     SET(FXDIV_BUILD_TESTS OFF CACHE BOOL "")
+     SET(FXDIV_BUILD_BENCHMARKS OFF CACHE BOOL "")
+@@ -710,7 +717,7 @@ ELSEIF(USE_CUDA)
+ ENDIF()
+ 
+ 
+-if (NOT MSVC)
++if (NOT MSVC AND NOT NNPACK_AND_FAMILY_DISABLED)
+   TARGET_LINK_LIBRARIES(torch_cpu PRIVATE fxdiv)
+ endif()
+ 
+diff --git a/caffe2/utils/CMakeLists.txt b/caffe2/utils/CMakeLists.txt
+index 27aabb1315..3c7845c67d 100644
+--- a/caffe2/utils/CMakeLists.txt
++++ b/caffe2/utils/CMakeLists.txt
+@@ -36,7 +36,7 @@ list(APPEND Caffe2_CPU_SRCS
+ # ---[ threadpool/pthreadpool* is a local modification of the NNPACK
+ # pthreadpool with a very similar interface. Neither NNPACK, nor this
+ # thread pool supports Windows.
+-if (NOT MSVC)
++if (NOT MSVC AND NOT NNPACK_AND_FAMILY_DISABLED)
+   add_definitions(-DUSE_INTERNAL_THREADPOOL_IMPL)
+   set(Caffe2_CPU_SRCS ${Caffe2_CPU_SRCS}
+           utils/threadpool/pthreadpool.cc
diff --git a/packages/py-torchtestcase/package.py b/packages/py-torchtestcase/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..29db01bd64dc306e6d7e096f62ee17bbb1b77aaa
--- /dev/null
+++ b/packages/py-torchtestcase/package.py
@@ -0,0 +1,20 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack.package import *
+
+
+class PyTorchtestcase(PythonPackage):
+    """Extends unittest.TestCase such that assertions support PyTorch tensors and parameters."""
+
+    homepage = "https://github.com/phohenecker/torch-test-case"
+    pypi = "torchtestcase/torchtestcase-2018.2.tar.gz"
+
+    version("2018.2", sha256="0061cde2eb79f09c9501fae675c52c799371606d52afcff8753c44e1a6254a00")
+    version("2018.1", sha256="691b053b0466aed40201e1b41f5a903b4df889a64272a18bcab4b1c8e9091cb4")
+    version("2017.1", sha256="f8bb0c4e3216087130f80c4237bb5e4c1e6de629d553f25fd7b85f6e33bf9b34")
+
+    depends_on("py-numpy@1.13.1:", type=("build", "run"))
+    depends_on("py-torch@0.4.0:", type=("build", "run"))
diff --git a/packages/py-umnn/package.py b/packages/py-umnn/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..545b1ec0d4470791d52a4c3e330eb0cfaeefc7b4
--- /dev/null
+++ b/packages/py-umnn/package.py
@@ -0,0 +1,20 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack import *
+
+
+class PyUmnn(PythonPackage):
+    """Official implementation of Unconstrained Monotonic Neural Networks (UMNN)."""
+
+    homepage = "https://github.com/AWehenkel/UMNN"
+    pypi = "umnn/umnn-1.71.tar.gz"
+
+    version("1.71", "bdd41d941a5d904e2217a960a9584922afad8068304976dc6fb0245e4f834996")
+
+    depends_on("python@3.6:", type=("build", "run"))
+    depends_on("py-hatchling", type="build")
+    depends_on("py-numpy", type=("build", "run"))
+    depends_on("py-torch@1.1:", type=("build", "run"))
diff --git a/packages/py-vbi/fix-install.patch b/packages/py-vbi/fix-install.patch
new file mode 100644
index 0000000000000000000000000000000000000000..d84cceb038b3541afde9fff63edd58b0545893e4
--- /dev/null
+++ b/packages/py-vbi/fix-install.patch
@@ -0,0 +1,12 @@
+diff --git a/pyproject.toml b/pyproject.toml
+index debc24e..2e0500b 100644
+--- a/pyproject.toml
++++ b/pyproject.toml
+@@ -58,7 +58,6 @@ path = "vbi/_version.py"
+ 
+ 
+ [tool.setuptools]
+-packages = ["vbi"]
+ include-package-data = true
+ 
+ [tool.setuptools.package-data]
diff --git a/packages/py-vbi/package.py b/packages/py-vbi/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..138893c5525043f17cde71ac71e85430c2415340
--- /dev/null
+++ b/packages/py-vbi/package.py
@@ -0,0 +1,45 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack import *
+
+
+class PyVbi(PythonPackage):
+
+    homepage = "https://vbi.readthedocs.io/latest/"
+    git = "https://github.com/ins-amu/vbi"
+    url = "https://github.com/ins-amu/vbi/archive/refs/tags/v0.1.3.tar.gz"
+
+    version("0.1.3", "54fa2062f44c9ec8219fae3c13c52a4bd17141b5467b982987673de0662c5255")
+    version("0.1.2", "6ccfeeec718be62a480002a8370130a3e3344955186f99ecbb15b646b68210d6")
+
+    patch('fix-install.patch')
+
+    depends_on("python@3.8:", type=("build","run"))
+    depends_on("py-setuptools", type="build")
+    depends_on("py-setuptools-scm", type="build")
+    depends_on("py-wheel", type="build")
+    depends_on("swig@4:", type="build")
+    depends_on("py-numpy", type=("build", "run"))
+    depends_on("py-scipy", type=("build", "run"))
+    depends_on("py-numba", type=("build", "run"))
+    depends_on("py-h5py", type=("build", "run"))
+    depends_on("py-pandas", type=("build", "run"))
+    depends_on("py-networkx", type=("build", "run"))
+    depends_on("py-nbconvert", type=("build", "run"))
+    depends_on("py-matplotlib", type=("build", "run"))
+    depends_on("py-tqdm", type=("build", "run"))
+    depends_on("py-sbi", type=("build", "run"))
+    depends_on("py-torch", type=("build", "run"))
+    depends_on("py-parameterized", type=("build", "run"))
+    depends_on("py-scikit-learn", type=("build", "run"))
+    depends_on("py-pycatch22", type=("build", "run"))
+    depends_on("py-pytest", type="test")
+    
+    @run_after("install")
+    @on_package_attributes(run_tests=True)
+    def install_test(self):
+        pytest = which("pytest")
+        pytest()
diff --git a/packages/py-xarray-einstats/package.py b/packages/py-xarray-einstats/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..520eb406167ef5622f5cd8d713830b4a4cd2f72a
--- /dev/null
+++ b/packages/py-xarray-einstats/package.py
@@ -0,0 +1,23 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack.package import *
+
+
+class PyXarrayEinstats(PythonPackage):
+    """Stats, linear algebra and einops for xarray"""
+
+    homepage = "https://github.com/arviz-devs/xarray-einstats"
+    pypi = "xarray_einstats/xarray_einstats-0.8.0.tar.gz"
+
+    version("0.8.0", sha256="7f1573f9bd4d60d6e7ed9fd27c4db39da51ec49bf8ba654d4602a139a6309d7f")
+    version("0.7.0", sha256="2d7b571b3bbad3cf2fd10c6c75fd949d247d14c29574184c8489d9d607278d38")
+    version("0.6.0", sha256="ace90601505cfbe2d374762e674557ed14e1725b024823372f7ef9fd237effad")
+
+    depends_on("python@3.10:", type=("build", "run"))
+    depends_on("py-flit-core@3.4:4", type="build")
+    depends_on("py-numpy@1.23:", type=("build", "run"))
+    depends_on("py-scipy@1.9:", type=("build", "run"))
+    depends_on("py-xarray@2022.09:", type=("build", "run"))
diff --git a/packages/py-zuko/package.py b/packages/py-zuko/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..9c2222731d6865b11507c988baa21701e72704a1
--- /dev/null
+++ b/packages/py-zuko/package.py
@@ -0,0 +1,20 @@
+# Copyright 2013-2024 Lawrence Livermore National Security, LLC and other
+# Spack Project Developers. See the top-level COPYRIGHT file for details.
+#
+# SPDX-License-Identifier: (Apache-2.0 OR MIT)
+
+from spack import *
+
+
+class PyZuko(PythonPackage):
+    """Python package that implements normalizing flows in PyTorch."""
+
+    homepage = "https://github.com/probabilists/zuko"
+    pypi = "zuko/zuko-1.3.1.tar.gz"
+
+    version("1.3.1", "00f246802d3f486183185529ba22e0b2bf691397e03b28150a5cf713fa0da758")
+
+    depends_on("python@3.9:", type=("build", "run"))
+    depends_on("py-setuptools", type="build")
+    depends_on("py-numpy@1.20.0:", type=("build", "run"))
+    depends_on("py-torch@1.12.0:", type=("build", "run"))
diff --git a/packages/wf-human-multi-area-model/package.py b/packages/wf-human-multi-area-model/package.py
index 7cafb2c150b15adbba1473d2b4c2af9058879952..5bcefe0d68f89a317a81109d36b88b26caa5cdb1 100644
--- a/packages/wf-human-multi-area-model/package.py
+++ b/packages/wf-human-multi-area-model/package.py
@@ -28,7 +28,7 @@ class WfHumanMultiAreaModel(Package):
     depends_on("py-nnmt@1.3.0:", type=("run", "test"))
     depends_on("py-dicthash@0.0.1:", type=("run", "test"))
     depends_on("py-networkx@3.1:", type=("run", "test"))
-    depends_on("py-notebook@6.5.4:", type=("run", "test"))
+    depends_on("py-notebook@6.4:", type=("run", "test"))
     depends_on("py-future@0.18.2:", type=("run", "test"))
 
     def install(self, spec, prefix):
diff --git a/spack.yaml b/spack.yaml
index 6e9692e0a0f55280e2652e5c369a8137faa48fef..95062095a8c24f6d77445b7c460a510a599307e7 100644
--- a/spack.yaml
+++ b/spack.yaml
@@ -56,6 +56,7 @@ spack:
     - py-tvb-ext-unicore
     - py-tvb-ext-xircuits@1.1.0
     - py-viziphant@0.4.0
+    - py-vbi
     - pynn-brainscales@9.0-a8
     - r-rgsl@0.1.1
     - r-sbtabvfgen@0.1