flake.nix 4.02 KB
Newer Older
1
2
{
  inputs = {
3
4
5
6
    crate2nix = {
      url = "github:nix-community/crate2nix";
      inputs.nixpkgs.follows = "tgi-nix/nixpkgs";
    };
7
8
9
    tgi-nix.url = "github:danieldk/tgi-nix";
    nixpkgs.follows = "tgi-nix/nixpkgs";
    flake-utils.url = "github:numtide/flake-utils";
Nicolas Patry's avatar
Nicolas Patry committed
10
    poetry2nix.url = "github:nix-community/poetry2nix";
11
12
13
14
    rust-overlay = {
      url = "github:oxalica/rust-overlay";
      inputs.nixpkgs.follows = "tgi-nix/nixpkgs";
    };
15
16
17
18
  };
  outputs =
    {
      self,
19
      crate2nix,
20
21
      nixpkgs,
      flake-utils,
22
      rust-overlay,
23
      tgi-nix,
Nicolas Patry's avatar
Nicolas Patry committed
24
      poetry2nix,
25
26
27
28
    }:
    flake-utils.lib.eachDefaultSystem (
      system:
      let
29
30
31
        cargoNix = crate2nix.tools.${system}.appliedCargoNix {
          name = "tgi";
          src = ./.;
32
          additionalCargoNixArgs = [ "--all-features" ];
33
        };
34
35
36
37
38
39
        config = {
          allowUnfree = true;
          cudaSupport = true;
        };
        pkgs = import nixpkgs {
          inherit config system;
40
41
42
43
          overlays = [
            rust-overlay.overlays.default
            tgi-nix.overlay
          ];
44
        };
Nicolas Patry's avatar
Nicolas Patry committed
45
        inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryEditablePackage;
46
        text-generation-server = mkPoetryEditablePackage { editablePackageSources = ./server; };
47
48
49
50
51
52
53
54
55
      in
      {
        devShells.default =
          with pkgs;
          mkShell {
            buildInputs =
              [
                openssl.dev
                pkg-config
56
57
58
59
60
61
                (rust-bin.stable.latest.default.override {
                  extensions = [
                    "rust-analyzer"
                    "rust-src"
                  ];
                })
62
63
64
65
66
              ]
              ++ (with python3.pkgs; [
                venvShellHook
                pip

67
                causal-conv1d
Nicolas Patry's avatar
Nicolas Patry committed
68
                click
69
                einops
Nicolas Patry's avatar
Nicolas Patry committed
70
                exllamav2
71
                fbgemm-gpu
Nicolas Patry's avatar
Nicolas Patry committed
72
                flashinfer
73
74
75
76
77
78
                flash-attn
                flash-attn-layer-norm
                flash-attn-rotary
                grpc-interceptor
                grpcio-reflection
                grpcio-status
Nicolas Patry's avatar
Nicolas Patry committed
79
                grpcio-tools
80
81
                hf-transfer
                loguru
82
                mamba-ssm
83
84
85
86
87
88
89
90
91
92
                marlin-kernels
                opentelemetry-api
                opentelemetry-exporter-otlp
                opentelemetry-instrumentation-grpc
                opentelemetry-semantic-conventions
                peft
                tokenizers
                torch
                transformers
                vllm
93

94
                cargoNix.workspaceMembers.text-generation-launcher.build
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

                (cargoNix.workspaceMembers.text-generation-router-v3.build.override {
                  crateOverrides = defaultCrateOverrides // {
                    aws-lc-rs = attrs: {
                      # aws-lc-rs does its own custom parsing of Cargo environment
                      # variables like DEP_.*_INCLUDE. However buildRustCrate does
                      # not use the version number, so the parsing fails.
                      postPatch = ''
                        substituteInPlace build.rs \
                          --replace-fail \
                          "assert!(!selected.is_empty()" \
                          "// assert!(!selected.is_empty()"
                      '';
                    };
                    rav1e = attrs: { env.CARGO_ENCODED_RUSTFLAGS = "-C target-feature=-crt-static"; };
                    text-generation-router-v3 = attrs: {
                      # We need to do the src/source root dance so that the build
                      # has access to the protobuf file.
                      src = ./.;
                      postPatch = "cd backends/v3";
                      buildInputs = [ protobuf ];
                    };
                  };
                })
119
120
121
122
123
124
125
126
127
128
129
130
131
132
              ]);

            venvDir = "./.venv";

            postVenv = ''
              unset SOURCE_DATE_EPOCH
            '';
            postShellHook = ''
              unset SOURCE_DATE_EPOCH
            '';
          };
      }
    );
}