Skip to content

armgit / uzu

Public Imported from GitHub
0

A high-performance inference engine for AI models

Upstream user-level stuff I have for uzu (#1044)

uuuvn023bf5d94c71
diff --git a/.gitignore b/.gitignore
index 271720091..ea21817ed 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,7 @@
# Nix
result
+.direnv
# Metal traces
*.gputrace
diff --git a/flake.nix b/flake.nix
index e37158624..48c8e1e8a 100644
--- a/flake.nix
+++ b/flake.nix
@@ -107,6 +107,8 @@
nodejs_26
pnpm_12
wasm-bindgen-cli_0_2_129 # Keep in sync with Cargo.toml.
+ (pkgs.callPackage ./scripts/safetensors-explorer.nix {})
+ (pkgs.callPackage ./scripts/urun.nix {})
evcxr
cargo-deny
cargo-nextest
@@ -118,7 +120,12 @@
critcmp
]
++ (with pkgs; lib.optionals stdenv.hostPlatform.isLinux [bindgen-env vulkan-env vulkan-tools shaderc spirv-tools lldb])
- ++ (with pkgs; lib.optionals stdenv.hostPlatform.isDarwin [cargo-swift tuist]);
+ ++ (with pkgs;
+ lib.optionals stdenv.hostPlatform.isDarwin [
+ (pkgs.callPackage ./scripts/cargo-instruments.nix {})
+ cargo-swift
+ tuist
+ ]);
hostToolchainDevshellPackages = commonDevshellPackages ++ [rustShimHostCC];
nixToolchainDevshellPackages = commonDevshellPackages ++ [rustShimNixCC];
diff --git a/scripts/cargo-instruments.nix b/scripts/cargo-instruments.nix
new file mode 100644
index 000000000..fceb6bbc2
--- /dev/null
+++ b/scripts/cargo-instruments.nix
@@ -0,0 +1,37 @@
+{
+ lib,
+ rustPlatform,
+ fetchFromGitHub,
+ pkg-config,
+ cmake,
+ curl,
+ openssl,
+ zlib,
+}:
+rustPlatform.buildRustPackage (finalAttrs: {
+ pname = "cargo-instruments";
+ version = "0.4.18";
+
+ src = fetchFromGitHub {
+ owner = "cmyr";
+ repo = "cargo-instruments";
+ tag = "v${finalAttrs.version}";
+ hash = "sha256-rLGsrzxQJRYJ/2goTy7Pa78Y22Rw9APD9YAECS9sbiE=";
+ };
+
+ cargoHash = "sha256-qcihtXcPNLbB/pG6JrA43z0dUQ6/JsBuabZFADQtziA=";
+
+ # The demangling test inspects a symbol optimized out in release builds.
+ checkType = "debug";
+
+ nativeBuildInputs = [pkg-config cmake];
+ buildInputs = [curl openssl zlib];
+
+ meta = {
+ description = "Profile Rust binaries on macOS using Xcode Instruments";
+ homepage = "https://github.com/cmyr/cargo-instruments";
+ license = lib.licenses.mit;
+ mainProgram = "cargo-instruments";
+ platforms = lib.platforms.darwin;
+ };
+})
diff --git a/scripts/safetensors-explorer.nix b/scripts/safetensors-explorer.nix
new file mode 100644
index 000000000..62165b3c9
--- /dev/null
+++ b/scripts/safetensors-explorer.nix
@@ -0,0 +1,26 @@
+{
+ lib,
+ rustPlatform,
+ fetchFromGitHub,
+}:
+rustPlatform.buildRustPackage (finalAttrs: {
+ pname = "safetensors-explorer";
+ version = "0.2.0";
+
+ src = fetchFromGitHub {
+ owner = "EricLBuehler";
+ repo = "safetensors_explorer";
+ tag = "v${finalAttrs.version}";
+ hash = "sha256-VHWaCxVDy7yVLLYDyQvjUzNnO3wmUcqdQMvM6CXRIH4=";
+ };
+
+ cargoHash = "sha256-KtJd5X5qG2ZAwMeI6cayUleF4otESk+3dJz+oe4mkx4=";
+
+ meta = {
+ description = "Terminal explorer for safetensors and GGUF files";
+ homepage = "https://github.com/EricLBuehler/safetensors_explorer";
+ license = lib.licenses.mit;
+ mainProgram = "safetensors_explorer";
+ platforms = lib.platforms.unix;
+ };
+})
diff --git a/scripts/urun b/scripts/urun
new file mode 100755
index 000000000..29bc4ebfb
--- /dev/null
+++ b/scripts/urun
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+usage() { echo 'usage: urun --on <host> -- <cmd> [args...]' >&2; exit 2; }
+die() { echo "urun: $*" >&2; exit 1; }
+quote() { printf '%q ' "$@"; }
+
+[[ $# -ge 4 && $1 == --on && -n $2 && $3 == -- ]] || usage
+host=$2; shift 3
+set -- env "$@"
+
+root=$(jj root 2>/dev/null || git rev-parse --show-toplevel) || die 'not in a jj/git repo'
+root=$(realpath "$root")
+home=$(realpath "$HOME")
+[[ $root == "$home/"* ]] || die "repo must be below \$HOME"
+rel=${root#"$home/"}
+cwd=$(realpath "$PWD")
+
+prefix=''
+if [[ -n ${DIRENV_FILE:-} ]]; then
+ dir=$(realpath "$(dirname "$DIRENV_FILE")" 2>/dev/null) || die 'active direnv directory does not resolve'
+ [[ $dir == "$root" || $dir == "$root/"* ]] || die 'active direnv file is outside the repo'
+ prefix="export DIRENV_LOG_FORMAT= && direnv allow $(quote "$rel${dir#"$root"}/$(basename "$DIRENV_FILE")") && "
+ set -- direnv exec . "$@"
+fi
+
+rsync -a --delete-after --mkpath -h --info=progress2 \
+ --filter=':- .gitignore' --exclude=.git --exclude=.jj --exclude=.direnv \
+ "$root/" "$host:$rel/" || { s=$?; (( s == 24 )) || exit "$s"; }
+
+ssh -t "$host" "${prefix}cd $(quote "$rel${cwd#"$root"}") && exec $(quote "$@")"
diff --git a/scripts/urun.nix b/scripts/urun.nix
new file mode 100644
index 000000000..5aa5de02a
--- /dev/null
+++ b/scripts/urun.nix
@@ -0,0 +1,14 @@
+{
+ writeShellApplication,
+ coreutils,
+ direnv,
+ git,
+ jujutsu,
+ openssh,
+ rsync,
+}:
+writeShellApplication {
+ name = "urun";
+ runtimeInputs = [coreutils direnv git jujutsu openssh rsync];
+ text = builtins.readFile ./urun;
+}