From e90ce0a240de0e2bf3c1e42a8df802e1847f5d86 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Wed, 11 Jun 2025 08:33:19 +0200 Subject: [PATCH] mistral-rs: 0.5.0 -> 0.7.0 Diff: https://github.com/EricLBuehler/mistral.rs/compare/refs/tags/v0.5.0...refs/tags/v0.7.0 Changelog: https://github.com/EricLBuehler/mistral.rs/releases/tag/v0.7.0 --- .../by-name/mi/mistral-rs/no-native-cpu.patch | 20 +++++---- pkgs/by-name/mi/mistral-rs/package.nix | 41 ++++++++++++------- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/pkgs/by-name/mi/mistral-rs/no-native-cpu.patch b/pkgs/by-name/mi/mistral-rs/no-native-cpu.patch index 07fb98d089a6..bb2e37542d12 100644 --- a/pkgs/by-name/mi/mistral-rs/no-native-cpu.patch +++ b/pkgs/by-name/mi/mistral-rs/no-native-cpu.patch @@ -1,16 +1,20 @@ diff --git a/.cargo/config.toml b/.cargo/config.toml -index 4abaaa83d..edc4d6710 100644 +index dde3bc53f..693808c6e 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml -@@ -1,12 +1,5 @@ --[target.x86_64-unknown-linux-gnu] --rustflags = ["-C", "target-cpu=native"] -- --[target.aarch64-apple-darwin] +@@ -1,15 +1,10 @@ -[build] -rustflags = ["-C", "target-cpu=native"] - - [target.wasm32-unknown-unknown] - rustflags = ["-C", "target-feature=+simd128"] + [target.aarch64-apple-darwin] + rustflags = [ +- "-C", "target-cpu=native", + "-C", "target-feature=+aes,+sha2,+fp16", + ] [target.x86_64-apple-darwin] + rustflags = [ +- "-C", "target-cpu=native", + "-C", "target-feature=-avx,-avx2", + ] + diff --git a/pkgs/by-name/mi/mistral-rs/package.nix b/pkgs/by-name/mi/mistral-rs/package.nix index 83f5f4946376..fb562cfe9ac5 100644 --- a/pkgs/by-name/mi/mistral-rs/package.nix +++ b/pkgs/by-name/mi/mistral-rs/package.nix @@ -48,7 +48,7 @@ let assert accelIsValid; (acceleration == "cuda") || (config.cudaSupport && acceleration == null); - minRequiredCudaCapability = "6.1"; # build fails with 6.0 + minRequiredCudaCapability = "8.0"; # build fails with 7.5 inherit (cudaPackages.flags) cudaCapabilities; cudaCapabilityString = if cudaCapability == null then @@ -74,20 +74,29 @@ let in rustPlatform.buildRustPackage (finalAttrs: { pname = "mistral-rs"; - version = "0.5.0"; + version = "0.7.0"; src = fetchFromGitHub { owner = "EricLBuehler"; repo = "mistral.rs"; tag = "v${finalAttrs.version}"; - hash = "sha256-mkxgssJUBtM1DYOhFfj8YKlW61/gd0cgPtMze7YZ9L8="; + hash = "sha256-2gE3LRm2oy6H+y6dRNnwYIjlaG67it16bfhfTk4CUTc="; }; patches = [ ./no-native-cpu.patch ]; - cargoHash = "sha256-YGGtS8gJJQKIgXxMWjO05ikSVdfVNs+cORbJ+Wf88y4="; + postPatch = + # LTO significantly increases the build time (12m -> 1h) + '' + substituteInPlace Cargo.toml \ + --replace-fail \ + "lto = true" \ + "lto = false" + ''; + + cargoHash = "sha256-nktoMh07PfGJ156XrKa1N/icB634cr9ybsHq/y9zHKo="; nativeBuildInputs = [ pkg-config @@ -121,18 +130,22 @@ rustPlatform.buildRustPackage (finalAttrs: { ++ lib.optionals (hostPlatform.isDarwin && metalSupport) [ "metal" ]; env = { + # metal (proprietary) is not available in the darwin sandbox. + # Hence, we must disable metal precompilation. + MISTRALRS_METAL_PRECOMPILE = 0; + SWAGGER_UI_DOWNLOAD_URL = let # When updating: # - Look for the version of `utoipa-swagger-ui` at: - # https://github.com/EricLBuehler/mistral.rs/blob/v/mistralrs-server/Cargo.toml + # https://github.com/EricLBuehler/mistral.rs/blob/v/Cargo.toml # - Look at the corresponding version of `swagger-ui` at: # https://github.com/juhaku/utoipa/blob/utoipa-swagger-ui-/utoipa-swagger-ui/build.rs#L21-L22 - swaggerUiVersion = "5.17.12"; + swaggerUiVersion = "5.17.14"; swaggerUi = fetchurl { url = "https://github.com/swagger-api/swagger-ui/archive/refs/tags/v${swaggerUiVersion}.zip"; - hash = "sha256-HK4z/JI+1yq8BTBJveYXv9bpN/sXru7bn/8g5mf2B/I="; + hash = "sha256-SBJE0IEgl7Efuu73n3HZQrFxYX+cn5UU5jrL4T5xzNw="; }; in "file://${swaggerUi}"; @@ -155,7 +168,7 @@ rustPlatform.buildRustPackage (finalAttrs: { ]; # swagger-ui will once more be copied in the target directory during the check phase - # See https://github.com/juhaku/utoipa/blob/utoipa-swagger-ui-7.1.0/utoipa-swagger-ui/build.rs#L168 + # See https://github.com/juhaku/utoipa/blob/utoipa-swagger-ui-9.0.2/utoipa-swagger-ui/build.rs#L168 # Not deleting the existing unpacked archive leads to a `PermissionDenied` error preCheck = '' rm -rf target/${stdenv.hostPlatform.rust.cargoShortTarget}/release/build/ @@ -166,23 +179,23 @@ rustPlatform.buildRustPackage (finalAttrs: { # - `cargo check ... --features=metal` (on darwin) requires the sandbox to be completely disabled checkFeatures = [ ]; - # Try to access internet checkFlags = [ + # Try to access internet "--skip=gguf::gguf_tokenizer::tests::test_encode_decode_gpt2" "--skip=gguf::gguf_tokenizer::tests::test_encode_decode_llama" "--skip=util::tests::test_parse_image_url" + "--skip=utils::tiktoken::tests::test_tiktoken_conversion" ]; nativeInstallCheckInputs = [ versionCheckHook ]; - versionCheckProgram = "${placeholder "out"}/bin/mistralrs-server"; - doInstallCheck = true; + # When started, mistralrs tries to load libcuda.so from the driver which is not available in the sandbox + # mistralrs: error while loading shared libraries: libcuda.so.1: cannot open shared object file: No such file or directory + doInstallCheck = !cudaSupport; passthru = { tests = { - version = testers.testVersion { package = mistral-rs; }; - withMkl = lib.optionalAttrs (hostPlatform.isLinux && hostPlatform.isx86_64) ( mistral-rs.override { acceleration = "mkl"; } ); @@ -200,7 +213,7 @@ rustPlatform.buildRustPackage (finalAttrs: { changelog = "https://github.com/EricLBuehler/mistral.rs/releases/tag/v${finalAttrs.version}"; license = lib.licenses.mit; maintainers = with lib.maintainers; [ GaetanLepage ]; - mainProgram = "mistralrs-server"; + mainProgram = "mistralrs"; platforms = if cudaSupport then lib.platforms.linux