Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rocm-6: bump packages to 6.3.1 and add missing packages #367695

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions pkgs/by-name/ol/ollama/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
buildGoModule,
fetchFromGitHub,
buildEnv,
linkFarm,
overrideCC,
makeWrapper,
stdenv,
addDriverRunpath,
nix-update-script,

cmake,
gcc-unwrapped,
gcc12,
gitMinimal,
clblast,
Expand All @@ -19,6 +19,7 @@
cudaPackages,
darwin,
autoAddDriverRunpath,
autoPatchelfHook,

nixosTests,
testers,
Expand All @@ -41,13 +42,13 @@ assert builtins.elem acceleration [
let
pname = "ollama";
# don't forget to invalidate all hashes each update
version = "0.5.1";
version = "0.5.4";

src = fetchFromGitHub {
owner = "ollama";
repo = "ollama";
rev = "v${version}";
hash = "sha256-llsK/rMK1jf2uneqgon9gqtZcbC9PuCDxoYfC7Ta6PY=";
hash = "sha256-JyP7A1+u9Vs6ynOKDwun1qLBsjN+CVHIv39Hh2TYa2U=";
fetchSubmodules = true;
};

Expand All @@ -68,17 +69,17 @@ let

rocmLibs = [
rocmPackages.clr
rocmPackages.hipblas-common
rocmPackages.hipblas
rocmPackages.rocblas
rocmPackages.rocsolver
rocmPackages.rocsparse
rocmPackages.rocm-device-libs
rocmPackages.rocm-smi
];
rocmClang = linkFarm "rocm-clang" { llvm = rocmPackages.llvm.clang; };
rocmPath = buildEnv {
name = "rocm-path";
paths = rocmLibs ++ [ rocmClang ];
paths = rocmLibs;
};

cudaLibs = [
Expand Down Expand Up @@ -143,6 +144,13 @@ goBuild {
ROCM_PATH = rocmPath;
CLBlast_DIR = "${clblast}/lib/cmake/CLBlast";
HIP_PATH = rocmPath;
CFLAGS = "-Wno-c++17-extensions -I${rocmPath}/include";
CXXFLAGS = "-Wno-c++17-extensions -I${rocmPath}/include";
}
// lib.optionalAttrs (enableRocm && (rocmPackages.clr.localGpuTargets or false) != false) {
# If rocm CLR is set to build for an exact set of targets reuse that target list,
# otherwise let ollama use its builtin defaults
HIP_ARCHS = lib.concatStringsSep ";" rocmPackages.clr.localGpuTargets;
}
// lib.optionalAttrs enableCuda {
CUDA_PATH = cudaPath;
Expand All @@ -152,6 +160,8 @@ goBuild {
[
cmake
gitMinimal
# rpaths of runners end up wrong without this
autoPatchelfHook
]
++ lib.optionals enableRocm [
rocmPackages.llvm.bintools
Expand All @@ -165,15 +175,11 @@ goBuild {
++ lib.optionals stdenv.hostPlatform.isDarwin metalFrameworks;

buildInputs =
lib.optionals enableRocm (rocmLibs ++ [ libdrm ])
[ gcc-unwrapped.lib ]
++ lib.optionals enableRocm (rocmLibs ++ [ libdrm ])
++ lib.optionals enableCuda cudaLibs
++ lib.optionals stdenv.hostPlatform.isDarwin metalFrameworks;

patches = [
# ollama's build script is unable to find hipcc
./rocm.patch
];

postPatch = ''
# replace inaccurate version number with actual release version
substituteInPlace version/version.go --replace-fail 0.0.0 '${version}'
Expand All @@ -192,10 +198,10 @@ goBuild {
'';

postInstall = lib.optionalString stdenv.hostPlatform.isLinux ''
# copy libggml_*.so and runners into lib
# https://github.com/ollama/ollama/blob/v0.4.4/llama/make/gpu.make#L90
mkdir -p $out/lib
cp -r dist/*/lib/* $out/lib/
# copy runner folders into $out/lib/ollama/runners/
# end result should be multiple folders inside runners/ each with their own ollama_llama_server binary
mkdir -p $out/lib/ollama/runners
cp -r llama/build/*/runners/* $out/lib/ollama/runners/
'';

postFixup =
Expand Down
13 changes: 0 additions & 13 deletions pkgs/by-name/ol/ollama/rocm.patch

This file was deleted.

4 changes: 3 additions & 1 deletion pkgs/by-name/uc/ucx/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ let
paths = rocmList;
};

# rocm build fails with gcc stdenv due to unrecognised arg parallel-jobs
stdenv' = if enableRocm then rocmPackages.stdenv else stdenv;
in
stdenv.mkDerivation rec {
stdenv'.mkDerivation rec {
pname = "ucx";
version = "1.17.0";

Expand Down
48 changes: 34 additions & 14 deletions pkgs/development/python-modules/torch/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
if cudaSupport then
magma-cuda-static
else if rocmSupport then
magma-hip
null
else
magma,
magma,
magma-hip,
magma-cuda-static,
# Use the system NCCL as long as we're targeting CUDA on a supported platform.
useSystemNccl ? (cudaSupport && !cudaPackages.nccl.meta.unsupported || rocmSupport),
Expand All @@ -36,6 +35,7 @@
symlinkJoin,
which,
pybind11,
pkg-config,
removeReferencesTo,

# Build inputs
Expand All @@ -54,6 +54,7 @@
cffi,
click,
typing-extensions,
six,
# ROCm build and `torch.compile` requires `triton`
tritonSupport ? (!stdenv.hostPlatform.isDarwin),
triton,
Expand All @@ -66,7 +67,13 @@
# (dependencies without cuda support).
# Instead we should rely on overlays and nixpkgsFun.
# (@SomeoneSerge)
_tritonEffective ? if cudaSupport then triton-cuda else triton,
_tritonEffective ?
if cudaSupport then
triton-cuda
else if rocmSupport then
rocmPackages.triton
else
triton,
triton-cuda,

# Unit tests
Expand All @@ -86,14 +93,13 @@

# dependencies for torch.utils.tensorboard
pillow,
six,
future,
tensorboard,
protobuf,

# ROCm dependencies
rocmSupport ? config.rocmSupport,
rocmPackages_5,
rocmPackages,
gpuTargets ? [ ],

vulkanSupport ? false,
Expand All @@ -113,8 +119,6 @@ let

triton = throw "python3Packages.torch: use _tritonEffective instead of triton to avoid divergence";

rocmPackages = rocmPackages_5;

setBool = v: if v then "1" else "0";

# https://github.com/pytorch/pytorch/blob/v2.4.0/torch/utils/cpp_extension.py#L1953
Expand Down Expand Up @@ -180,7 +184,7 @@ let
clr
rccl
miopen
miopengemm
aotriton
rocrand
rocblas
rocsparse
Expand All @@ -192,10 +196,12 @@ let
rocfft
rocsolver
hipfft
hiprand
hipsolver
hipblas-common
hipblas
hipblaslt
rocminfo
rocm-thunk
rocm-comgr
rocm-device-libs
rocm-runtime
Expand All @@ -212,6 +218,7 @@ let
brokenConditions = attrsets.filterAttrs (_: cond: cond) {
"CUDA and ROCm are mutually exclusive" = cudaSupport && rocmSupport;
"CUDA is not targeting Linux" = cudaSupport && !stdenv.hostPlatform.isLinux;
"ROCm 6 is currently not compatible with magma" = rocmSupport && effectiveMagma != null;
"Unsupported CUDA version" =
cudaSupport
&& !(builtins.elem cudaPackages.cudaMajorVersion [
Expand All @@ -225,8 +232,6 @@ let
# In particular, this triggered warnings from cuda's `aliases.nix`
"Magma cudaPackages does not match cudaPackages" =
cudaSupport && (effectiveMagma.cudaPackages.cudaVersion != cudaPackages.cudaVersion);
"Rocm support is currently broken because `rocmPackages.hipblaslt` is unpackaged. (2024-06-09)" =
rocmSupport;
};

git-unroll = fetchFromGitea {
Expand Down Expand Up @@ -306,6 +311,10 @@ buildPythonPackage rec {
"# Upstream: set(CUDAToolkit_ROOT"
substituteInPlace third_party/gloo/cmake/Cuda.cmake \
--replace-warn "find_package(CUDAToolkit 7.0" "find_package(CUDAToolkit"
substituteInPlace third_party/NNPACK/CMakeLists.txt --replace "PYTHONPATH=" 'PYTHONPATH=$ENV{PYTHONPATH}:'
# flag from cmakeFlags doesn't work, not clear why
# setting it at the top of NNPACK's own CMakeLists does
sed -i '2s;^;set(PYTHON_SIX_SOURCE_DIR ${six.src})\n;' third_party/NNPACK/CMakeLists.txt
''
+ lib.optionalString rocmSupport ''
# https://github.com/facebookincubator/gloo/pull/297
Expand Down Expand Up @@ -388,6 +397,10 @@ buildPythonPackage rec {
# We only do an imports check, so do not build tests either.
BUILD_TEST = setBool false;

# ninja hook doesn't automatically turn on ninja
# because pytorch setup.py is responsible for this
CMAKE_GENERATOR = "Ninja";

# Unlike MKL, oneDNN (née MKLDNN) is FOSS, so we enable support for
# it by default. PyTorch currently uses its own vendored version
# of oneDNN through Intel iDeep.
Expand All @@ -398,14 +411,15 @@ buildPythonPackage rec {
# Also avoids pytorch exporting the headers of pybind11
USE_SYSTEM_PYBIND11 = true;

# NB technical debt: building without NNPACK as workaround for missing `six`
USE_NNPACK = 0;
# Multicore CPU convnet support
USE_NNPACK = 1;

# Explicitly enable MPS for Darwin
USE_MPS = setBool stdenv.hostPlatform.isDarwin;

cmakeFlags =
[
(lib.cmakeFeature "PYTHON_SIX_SOURCE_DIR" "${six.src}")
# (lib.cmakeBool "CMAKE_FIND_DEBUG_MODE" true)
(lib.cmakeFeature "CUDAToolkit_VERSION" cudaPackages.cudaVersion)
]
Expand Down Expand Up @@ -454,6 +468,8 @@ buildPythonPackage rec {

env =
{
# Builds faster without this and we don't have enough inputs that cmd length is an issue
NIX_CC_USE_RESPONSE_FILE = 0;
# disable warnings as errors as they break the build on every compiler
# bump, among other things.
# Also of interest: pytorch ignores CXXFLAGS uses CFLAGS for both C and C++:
Expand All @@ -463,6 +479,9 @@ buildPythonPackage rec {
}
// lib.optionalAttrs vulkanSupport {
VULKAN_SDK = shaderc.bin;
}
// lib.optionalAttrs rocmSupport {
AOTRITON_INSTALLED_PREFIX = "${rocmPackages.aotriton}";
};

nativeBuildInputs =
Expand All @@ -471,6 +490,7 @@ buildPythonPackage rec {
which
ninja
pybind11
pkg-config
removeReferencesTo
]
++ lib.optionals cudaSupport (
Expand Down Expand Up @@ -516,7 +536,7 @@ buildPythonPackage rec {
]
)
++ lib.optionals rocmSupport [ rocmPackages.llvm.openmp ]
++ lib.optionals (cudaSupport || rocmSupport) [ effectiveMagma ]
++ lib.optionals (effectiveMagma != null && (cudaSupport || rocmSupport)) [ effectiveMagma ]
++ lib.optionals stdenv.hostPlatform.isLinux [ numactl ]
++ lib.optionals stdenv.hostPlatform.isDarwin [
apple-sdk_13
Expand Down
1 change: 0 additions & 1 deletion pkgs/development/python-modules/torchaudio/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ let
hipsolver
hipblas
rocminfo
rocm-thunk
rocm-comgr
rocm-device-libs
rocm-runtime
Expand Down
Loading
Loading