Skip to content

armgit / uzu

Public Imported from GitHub
0

A high-performance inference engine for AI models

Nix (#397)

uuuvn6971794761f8
diff --git a/.cursorrules b/.cursorrules
deleted file mode 120000
index 95e38a6a9..000000000
--- a/.cursorrules
+++ /dev/null
@@ -1 +0,0 @@
-agents/AGENTS.md
\ No newline at end of file
diff --git a/.cursorrules b/.cursorrules
new file mode 100644
index 000000000..95e38a6a9
--- /dev/null
+++ b/.cursorrules
@@ -0,0 +1 @@
+agents/AGENTS.md
\ No newline at end of file
diff --git a/.envrc b/.envrc
new file mode 100644
index 000000000..3550a30f2
--- /dev/null
+++ b/.envrc
@@ -0,0 +1 @@
+use flake
diff --git a/.gitignore b/.gitignore
index db59cb447..d3bf51e56 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,9 @@
*.proptest-regressions
.idea/
+# Nix
+result
+
# Metal traces
*.gputrace
*.trace
@@ -30,4 +33,4 @@ tools/gpu_trace/*.json
# Swift
.build/
.swiftpm/
-Package.resolved
\ No newline at end of file
+Package.resolved
diff --git a/Cargo.lock b/Cargo.lock
index ce578e6f8..cb1fe3632 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -8470,9 +8470,9 @@ checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4"
[[package]]
name = "xgrammar-rs"
-version = "0.1.32"
+version = "0.1.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b6b801ffa86a1ff8637c04b7512350a3e71dc879dbdc0c142ed3ee27c0d0b540"
+checksum = "2f62aaf862c4c02642e381bc17172be4096889bb3834aa47a1bead94df70f0c6"
dependencies = [
"autocxx",
"autocxx-build",
diff --git a/Cargo.toml b/Cargo.toml
index 653e6811c..09439247a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -56,7 +56,7 @@ download-manager = { path = "crates/download-manager", default-features = false
mock-registry = { path = "crates/mock-registry", default-features = false }
benchmarks = { path = "crates/benchmarks", default-features = false }
uzu = { path = "crates/uzu", default-features = false }
-xgrammar = { package = "xgrammar-rs", version = "0.1", features = ["hf"] }
+xgrammar = { package = "xgrammar-rs", version = "0.1.33", features = ["hf"] }
half = { version = "2.7", features = ["bytemuck", "num-traits"] }
ndarray = "0.17"
serde = { version = "1.0", features = ["derive"] }
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 000000000..05c424f67
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,98 @@
+{
+ "nodes": {
+ "crane": {
+ "locked": {
+ "lastModified": 1778106249,
+ "narHash": "sha256-cM/AuKy5tMhwOOQIbha8ZRRMHVfNf7cv2aljIw+qoCg=",
+ "owner": "ipetkov",
+ "repo": "crane",
+ "rev": "6d015ea29630b7ad2402841386da2cb617a470a7",
+ "type": "github"
+ },
+ "original": {
+ "owner": "ipetkov",
+ "repo": "crane",
+ "type": "github"
+ }
+ },
+ "flake-utils": {
+ "inputs": {
+ "systems": "systems"
+ },
+ "locked": {
+ "lastModified": 1731533236,
+ "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
+ "type": "github"
+ },
+ "original": {
+ "owner": "numtide",
+ "repo": "flake-utils",
+ "type": "github"
+ }
+ },
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1777954456,
+ "narHash": "sha256-hGdgeU2Nk87RAuZyYjyDjFL6LK7dAZN5RE9+hrDTkDU=",
+ "owner": "nixos",
+ "repo": "nixpkgs",
+ "rev": "549bd84d6279f9852cae6225e372cc67fb91a4c1",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nixos",
+ "ref": "nixos-unstable",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "crane": "crane",
+ "flake-utils": "flake-utils",
+ "nixpkgs": "nixpkgs",
+ "rust-overlay": "rust-overlay"
+ }
+ },
+ "rust-overlay": {
+ "inputs": {
+ "nixpkgs": [
+ "nixpkgs"
+ ]
+ },
+ "locked": {
+ "lastModified": 1778469574,
+ "narHash": "sha256-NTZzJ7xJvMXOonYqut3WLUhryeZj5QuuL0ANcqS7d30=",
+ "owner": "oxalica",
+ "repo": "rust-overlay",
+ "rev": "4852a8aa041c94af55e136cde5b8b6d42c3563e8",
+ "type": "github"
+ },
+ "original": {
+ "owner": "oxalica",
+ "repo": "rust-overlay",
+ "type": "github"
+ }
+ },
+ "systems": {
+ "locked": {
+ "lastModified": 1681028828,
+ "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
+ "owner": "nix-systems",
+ "repo": "default",
+ "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-systems",
+ "repo": "default",
+ "type": "github"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 000000000..9ca30c58c
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,80 @@
+{
+ description = "A high-performance inference engine for AI models";
+ inputs = {
+ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
+ rust-overlay = {
+ url = "github:oxalica/rust-overlay";
+ inputs.nixpkgs.follows = "nixpkgs";
+ };
+ crane.url = "github:ipetkov/crane";
+ flake-utils.url = "github:numtide/flake-utils";
+ };
+ outputs = {
+ nixpkgs,
+ rust-overlay,
+ crane,
+ flake-utils,
+ ...
+ }:
+ flake-utils.lib.eachDefaultSystem (
+ system: let
+ overlays = [(import rust-overlay)];
+ pkgs = import nixpkgs {
+ inherit system overlays;
+ };
+ rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
+ craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
+
+ nativeBuildInputs = with pkgs;
+ [
+ # for xgrammar-rs
+ cmake
+ ]
+ ++ (pkgs.lib.optionals pkgs.stdenv.isDarwin [
+ # impure hack to get metal toolchain
+ (lib.hiPrio (writeShellScriptBin "xcrun" ''
+ unset DEVELOPER_DIR
+ exec /usr/bin/xcrun "$@"
+ ''))
+ ]);
+
+ mirai = craneLib.buildPackage {
+ pname = "mirai";
+ src = ./.;
+
+ cargoExtraArgs = "-p cli";
+ installPhaseCommand = ''
+ mkdir -p $out/bin
+ install -Dm755 target/release/cli $out/bin/mirai
+ '';
+
+ inherit nativeBuildInputs;
+
+ doCheck = false;
+ };
+ in {
+ formatter = pkgs.alejandra;
+
+ packages = {
+ inherit mirai;
+ default = mirai;
+ };
+
+ devShells.default = pkgs.mkShell {
+ nativeBuildInputs =
+ nativeBuildInputs
+ ++ (with pkgs; [
+ nixd
+ uv
+ wasmtime
+ evcxr
+ cargo-deny
+ cargo-nextest
+ cargo-flamegraph
+ cargo-show-asm
+ critcmp
+ ]);
+ };
+ }
+ );
+}