A high-performance inference engine for AI models
A bit better ci (#620)
uuuvnbec6a841ace6
diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.ymlindex f224eedf3..408dfb32d 100644--- a/.github/actions/setup/action.yml+++ b/.github/actions/setup/action.yml@@ -26,25 +26,26 @@ inputs:description: "Install bindings requirements"required: falsedefault: 'false'- linux:- description: "Install Linux system dependencies"- required: false- default: 'false'runs:using: compositesteps:- - if: inputs.target != ''+ - if: runner.os == 'Linux'run: |- if ! command -v rustup >/dev/null 2>&1; then- echo "rustup not installed, skipping target reset"- exit 0- fi- rustup self update >/dev/null- rustup target remove "${{ inputs.target }}" 2>/dev/null || true- rm -rf "$(rustc --print sysroot)/lib/rustlib/${{ inputs.target }}"+ sudo apt-get update+ sudo apt-get install -y libasound2-dev build-essential pkg-config cmakeshell: bash+ # - if: runner.os == 'Linux'+ # run: |+ # sudo mkdir -p /data/cargo+ # sudo chown runner:runner /data/cargo++ # mkdir -p ~/.cargo+ # rm -rf ~/.cargo/registry && ln -sfn /data/cargo/registry ~/.cargo/registry+ # rm -rf ~/.cargo/git && ln -sfn /data/cargo/git ~/.cargo/git+ # shell: bash+- uses: dtolnay/rust-toolchain@stablewith:targets: ${{ inputs.target }}@@ -54,12 +55,11 @@ runs:targets: ${{ inputs.target }}components: ${{ inputs.linters == 'true' && 'rustfmt,clippy' || '' }}- - if: inputs.linux == 'true'- run: sudo apt-get update && sudo apt-get install -y libasound2-dev- shell: bash-+ # TODO: drop wasi when pure wasm is done and switch to latest- if: inputs.target == 'wasm32-wasip1-threads'uses: bytecodealliance/actions/wasmtime/setup@v1+ with:+ version: "46.0.0"- if: inputs.linters == 'true'run: |diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.ymlindex a216905ee..ecc6b6162 100644--- a/.github/workflows/tests.yml+++ b/.github/workflows/tests.yml@@ -22,7 +22,7 @@ defaults:jobs:linters:name: linters- runs-on: macos-26+ runs-on: [self-hosted, macos, arm64]steps:- uses: actions/checkout@v6@@ -53,11 +53,6 @@ jobs:if: ${{ always() && steps.setup.outcome == 'success' }}run: cargo +nightly clippy --workspace --all-targets -- -D warnings- - name: Lint mirai app with clippy- if: ${{ always() && steps.setup.outcome == 'success' }}- working-directory: apps/mirai- run: cargo +nightly clippy --workspace --all-targets -- -D warnings-- name: Check that Cargo.lock is consistent with Cargo.tomlif: ${{ always() && steps.setup.outcome == 'success' }}run: |@@ -72,71 +67,79 @@ jobs:if: ${{ always() && steps.setup.outcome == 'success' }}run: cargo tools sync --check+ linters-gpui-app:+ name: linters (gpui app)+ runs-on: [self-hosted, macos, arm64]++ steps:+ - uses: actions/checkout@v6+ - id: setup+ uses: ./.github/actions/setup+ with:+ linters: true+ metal: true++ - name: Lint mirai app with clippy+ if: ${{ always() && steps.setup.outcome == 'success' }}+ working-directory: apps/mirai+ run: cargo +nightly clippy --workspace --all-targets -- -D warnings+tests:- name: ${{ matrix.backend }}- ${{ matrix.host == 'linux' && ' (linux)' || '' }}- ${{ matrix.grammar && ' (grammar)' || '' }}- ${{ matrix.target != '' && format(' ({0})', matrix.target) || '' }}- runs-on: ${{ matrix.host == 'linux' && 'ubuntu-latest' || fromJSON('["self-hosted","macos","arm64"]') }}+ name: ${{ matrix.host }}${{ matrix.target && format(' ({0})', matrix.target) }}+ runs-on: ${{ matrix.host == 'linux' && 'uzu-n4std16' || fromJSON('["self-hosted","macos","arm64"]') }}strategy:matrix:- backend: [ 'cpu', 'metal' ]- host: [ 'macos' ]- target: [ '' ]include:- - grammar: true- - backend: 'cpu'- host: 'macos'+ - host: 'macos'+ tests: true+ benches: true+ - host: 'linux'+ crates: ['cli']+ - host: 'linux'target: 'wasm32-wasip1-threads'- grammar: false- - backend: 'cpu'- host: 'linux'- target: ''- grammar: false+ crates: ['uzu']+ tests: 'kernels'+ - host: 'linux'+ target: 'wasm32-unknown-unknown'+ crates: ['kiban']env:CARGO_ENCODED_RUSTFLAGS: "-Dwarnings"HF_TOKEN: ${{ secrets.HF_TOKEN }}- FEATURE_FLAGS: >-- ${{ matrix.target != '' && format('--target {0}', matrix.target) || '' }}- ${{ matrix.backend != 'cpu' && format('--features {0}', matrix.backend) || '' }}- ${{ matrix.grammar && '--features grammar' || '' }}steps:- uses: actions/checkout@v6- uses: ./.github/actions/setupwith:- metal: ${{ matrix.backend == 'metal' }}- test_data: ${{ matrix.host != 'linux' }}- nextest: ${{ matrix.host != 'linux' }}+ metal: ${{ matrix.host == 'macos' && 'true' || 'false' }}+ test_data: ${{ matrix.tests == true && 'true' || 'false' }}+ nextest: ${{ matrix.tests && 'true' || 'false' }}target: ${{ matrix.target }}- linux: ${{ matrix.host == 'linux' }}- name: Build crates- run: cargo +stable build --no-default-features $FEATURE_FLAGS ${{ matrix.target == 'wasm32-wasip1-threads' && '-p uzu' || '' }} ${{ matrix.host == 'linux' && '-p cli --features backend-cpu,capability-cli' || '' }}-- # Temporary step to check crates that migrated to wasm.- # New value to matrix was not added intentionally because the whole project is not wasm supported.- - name: Build wasm supported crates- if: ${{ matrix.target == 'wasm32-wasip1-threads' }}run: |- rustup +stable target add wasm32-unknown-unknown- cargo +stable build -p kiban --target wasm32-unknown-unknown+ cargo +stable build \+ ${{ matrix.target && format('--target {0}', matrix.target) }} \+ ${{ matrix.crates && format('-p {0}', join(matrix.crates, ' -p ')) }}- name: Build benches- if: ${{ matrix.backend != 'cpu' }}- run: cargo +nightly bench --no-run --no-default-features $FEATURE_FLAGS+ if: ${{ matrix.benches }}+ run: |+ cargo +nightly bench --no-run \+ ${{ matrix.target && format('--target {0}', matrix.target) }} \+ ${{ matrix.crates && format('-p {0}', join(matrix.crates, ' -p ')) }}- name: Run tests- if: ${{ matrix.backend != 'cpu' && matrix.grammar || matrix.backend == 'cpu' && !matrix.grammar && matrix.target == 'wasm32-wasip1-threads' }}+ if: ${{ matrix.tests }}run: |- cargo +nightly nextest run --profile=ci --no-default-features $FEATURE_FLAGS \- ${{ matrix.target == 'wasm32-wasip1-threads' && '-p backend-uzu backends::common::kernel::tests --lib' || '' }}+ cargo +nightly nextest run --profile=ci \+ ${{ matrix.target && format('--target {0}', matrix.target) }} \+ ${{ matrix.tests == 'kernels' && '-p backend-uzu backends::common::kernel::tests --lib' }}validate-bindings:name: validate-bindings- runs-on: [ self-hosted, macos, arm64 ]+ runs-on: [self-hosted, macos, arm64]steps:- uses: actions/checkout@v6@@ -145,13 +148,6 @@ jobs:metal: truebindings: true- - name: "Reset existing rustup toolchains on self-hosted runner"- run: |- if command -v rustup >/dev/null; then- rustup toolchain uninstall stable 2>/dev/null || true- rustup toolchain uninstall nightly 2>/dev/null || true- fi-- name: "Setup"run: |cargo tools setup@@ -178,11 +174,12 @@ jobs:completed:name: completedruns-on: ubuntu-latest- needs: [ linters, tests, validate-bindings ]+ needs: [linters, linters-gpui-app, tests, validate-bindings]if: ${{ always() }}steps:- run: |[ "${{ needs.linters.result }}" = success ]+ [ "${{ needs.linters-gpui-app.result }}" = success ][ "${{ needs.tests.result }}" = success ][ "${{ needs.validate-bindings.result }}" = success ]diff --git a/Cargo.lock b/Cargo.lockindex 6a98b9a8e..411b166b8 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -486,11 +486,8 @@ dependencies = ["indicatif","is_close","itertools 0.14.0",- "libc","libm","memmap2",- "minijinja",- "minijinja-contrib","monostate","mtl-rs","ndarray",@@ -507,7 +504,6 @@ dependencies = ["rand 0.10.2","rand_distr","rangemap",- "regex","rhai","rstest","rustix",@@ -516,7 +512,6 @@ dependencies = ["serde_json","shoji","syn 2.0.118",- "sysinfo","tempfile","test-runner","test-tag",@@ -527,7 +522,6 @@ dependencies = ["walkdir","xgrammar-rs","xxhash-rust",- "zerocopy",][[package]]diff --git a/Cargo.toml b/Cargo.tomlindex 39571b6d9..12b5b21a1 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -82,7 +82,6 @@ metal = { package = "mtl-rs", version = "0.1.14" }block2 = "0.6"bytemuck = "1.23"bytesize = "2"-zerocopy = "0.8.27"xxhash-rust = "0.8.15"memmap2 = "0.9.8"num-traits = "0.2"diff --git a/crates/backend-uzu/Cargo.toml b/crates/backend-uzu/Cargo.tomlindex cccee27d9..f90539cd8 100644--- a/crates/backend-uzu/Cargo.toml+++ b/crates/backend-uzu/Cargo.toml@@ -9,6 +9,47 @@ repository.workspace = truelicense.workspace = truebuild = "build/main.rs"+[lints]+workspace = true++[features]+default = ["metal", "grammar"]++metal = [+ "dep:clang-ast",+ "dep:objc2",+ "dep:objc2-foundation",+ "dep:bytesize",+ "dep:metal",+ "dep:obfstr",+]++grammar = ["dep:xgrammar"]++[build-dependencies]+anyhow.workspace = true+async-trait.workspace = true+bindgen.workspace = true+walkdir.workspace = true+depfile.workspace = true+derive_more.workspace = true+tempfile.workspace = true+serde.workspace = true+serde_json = { workspace = true, features = ["unbounded_depth"] }+futures.workspace = true+tokio = { workspace = true, features = ["full"] }+blake3.workspace = true+quote.workspace = true+proc-macro2.workspace = true+syn.workspace = true+prettyplease.workspace = true+itertools.workspace = true+cbindgen.workspace = true+rhai.workspace = true++[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos"))'.build-dependencies]+clang-ast = { workspace = true, optional = true }+[dependencies]proc-macros.workspace = truebitflags.workspace = true@@ -22,18 +63,12 @@ monostate.workspace = truethiserror.workspace = truetokenizers.workspace = truerangemap.workspace = true-bytemuck.workspace = true-zerocopy = { workspace = true, features = ["derive"] }+bytemuck = { workspace = true, features = ["derive"] }xxhash-rust = { workspace = true, features = ["xxh3"] }memmap2.workspace = truenum-traits.workspace = true-regex.workspace = true-libc.workspace = truelibm.workspace = true-minijinja.workspace = true-minijinja-contrib.workspace = truerand.workspace = true-sysinfo.workspace = trueitertools.workspace = trueschemars.workspace = truerustix.workspace = true@@ -42,8 +77,6 @@ parking_lot = { workspace = true, features = ["send_guard"] }async-stream.workspace = truetokio-util.workspace = true-xgrammar = { workspace = true, optional = true }-[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos"))'.dependencies]objc2 = { workspace = true, optional = true }objc2-foundation = { workspace = true, optional = true }@@ -51,6 +84,9 @@ bytesize = { workspace = true, optional = true }metal = { workspace = true, optional = true }obfstr = { workspace = true, optional = true }+[target.'cfg(not(target_arch = "wasm32"))'.dependencies]+xgrammar = { workspace = true, optional = true }+[dev-dependencies]test-tag.workspace = truetest-runner = { workspace = true, features = ["nightly-harness"] }@@ -67,43 +103,3 @@ rstest.workspace = true[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]criterion = { workspace = true, default-features = true }proptest = { workspace = true, default-features = true }--[build-dependencies]-anyhow.workspace = true-async-trait.workspace = true-bindgen.workspace = true-walkdir.workspace = true-depfile.workspace = true-derive_more.workspace = true-tempfile.workspace = true-serde.workspace = true-serde_json = { workspace = true, features = ["unbounded_depth"] }-futures.workspace = true-tokio = { workspace = true, features = ["full"] }-blake3.workspace = true-quote.workspace = true-proc-macro2.workspace = true-syn.workspace = true-prettyplease.workspace = true-itertools.workspace = true-cbindgen.workspace = true-rhai.workspace = true--[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "visionos"))'.build-dependencies]-clang-ast = { workspace = true, optional = true }--[features]-default = ["metal", "grammar"]--metal = [- "dep:clang-ast",- "dep:objc2",- "dep:objc2-foundation",- "dep:bytesize",- "dep:metal",- "dep:obfstr",-]-grammar = ["dep:xgrammar"]--[lints]-workspace = truediff --git a/crates/backend-uzu/build/main.rs b/crates/backend-uzu/build/main.rsindex 564194244..3f572a34e 100644--- a/crates/backend-uzu/build/main.rs+++ b/crates/backend-uzu/build/main.rs@@ -14,15 +14,11 @@ mod metal;#[tokio::main(flavor = "current_thread")]async fn main() -> anyhow::Result<()> {println!("cargo::rerun-if-changed=.");-- if env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("ios") && env::var("IPHONEOS_DEPLOYMENT_TARGET").is_err() {- println!("cargo::rustc-env=IPHONEOS_DEPLOYMENT_TARGET=26.4");- }-if envs::build_always() {println!("cargo::rerun-if-changed=/var/empty/hack_nonexistent_file_to_always_rerun");}+ let target_arch = env::var("CARGO_CFG_TARGET_ARCH")?;let target_os = env::var("CARGO_CFG_TARGET_OS")?;let metal_backend = cfg!(feature = "metal") && matches!(target_os.as_ref(), "macos" | "ios" | "tvos" | "visionos");@@ -31,7 +27,7 @@ async fn main() -> anyhow::Result<()> {println!("cargo::rustc-cfg=metal_backend");}- let grammar_xgrammar = cfg!(feature = "grammar");+ let grammar_xgrammar = cfg!(feature = "grammar") && target_arch != "wasm32";println!("cargo::rustc-check-cfg=cfg(grammar_xgrammar)");if grammar_xgrammar {println!("cargo::rustc-cfg=grammar_xgrammar");@@ -53,11 +49,14 @@ async fn main() -> anyhow::Result<()> {let enum_paths = EnumPaths::from_gpu_types(&gpu_types).context("Failed to build enum path map")?;- let compilers: Vec<Box<dyn Compiler>> = vec![- Box::new(cpu::CpuCompiler::new()?),- #[cfg(all(feature = "metal", target_os = "macos"))]- Box::new(metal::MetalCompiler::new()?),- ];+ let mut compilers: Vec<Box<dyn Compiler>> = Vec::new();++ compilers.push(Box::new(cpu::CpuCompiler::new()?));++ #[cfg(all(feature = "metal", target_os = "macos"))]+ if metal_backend {+ compilers.push(Box::new(metal::MetalCompiler::new()?));+ }let backends_kernels = try_join_all(compilers.iter().map(|c| c.build(&gpu_types, &enum_paths))).await?;diff --git a/crates/backend-uzu/src/speculators/ngram_speculator.rs b/crates/backend-uzu/src/speculators/ngram_speculator.rsindex cd8e5af60..0cea21c3c 100644--- a/crates/backend-uzu/src/speculators/ngram_speculator.rs+++ b/crates/backend-uzu/src/speculators/ngram_speculator.rs@@ -1,8 +1,7 @@use std::{collections::HashMap, ops::Deref};-use bytemuck::cast_slice;+use bytemuck::{Pod, Zeroable, cast_slice, from_bytes};use xxhash_rust::xxh3::xxh3_64;-use zerocopy::{FromBytes, Immutable, KnownLayout};use crate::speculators::speculator::Speculator;@@ -34,7 +33,7 @@ fn apply_temperature(}#[repr(C)]-#[derive(FromBytes, KnownLayout, Immutable)]+#[derive(Clone, Copy, Pod, Zeroable)]struct TaggedTableHeader {hashtable_size: u32,top_k: u32,@@ -59,7 +58,7 @@ impl TaggedTableLayout {bytes: &[u8],offset: usize,) -> (Self, usize) {- let header = TaggedTableHeader::ref_from_bytes(&bytes[offset..offset + HEADER_SIZE]).unwrap();+ let header = from_bytes::<TaggedTableHeader>(&bytes[offset..offset + HEADER_SIZE]);assert!(header.hashtable_size > 0, "hashtable_size must be > 0");assert!(header.top_k > 0, "top_k must be > 0");diff --git a/crates/uzu/Cargo.toml b/crates/uzu/Cargo.tomlindex 69025af8f..d8d4a48f6 100644--- a/crates/uzu/Cargo.toml+++ b/crates/uzu/Cargo.toml@@ -67,7 +67,6 @@ anyhow.workspace = truebitflags.workspace = trueunicode-segmentation.workspace = trueunicode-width.workspace = true-rodio.workspace = trueuniffi = { workspace = true, optional = true }napi = { workspace = true, optional = true }napi-derive = { workspace = true, optional = true }@@ -79,13 +78,14 @@ wasm-bindgen = { workspace = true, optional = true }serde-wasm-bindgen = { workspace = true, optional = true }wasm-bindgen-futures = { workspace = true, optional = true }tsify = { workspace = true, optional = true }-iocraft = { workspace = true, optional = true }-indoc = { workspace = true, optional = true }[target.'cfg(not(target_family = "wasm"))'.dependencies]+iocraft = { workspace = true, optional = true }+indoc = { workspace = true, optional = true }backend-remote.workspace = truenagare.workspace = truedownload-manager.workspace = true+rodio.workspace = trueserde.workspace = trueserde_json.workspace = truethiserror.workspace = truediff --git a/crates/uzu/src/lib.rs b/crates/uzu/src/lib.rsindex 9e0079dd4..db18ad8e8 100644--- a/crates/uzu/src/lib.rs+++ b/crates/uzu/src/lib.rs@@ -28,7 +28,7 @@ fn uzu(m: &pyo3::Bound<'_, pyo3::types::PyModule>) -> pyo3::PyResult<()> {#[cfg(feature = "bindings-pyo3")]pyo3_stub_gen::define_stub_info_gatherer!(pyo3_bindings_annotations);-#[cfg(feature = "capability-cli")]+#[cfg(all(feature = "capability-cli", not(target_family = "wasm")))]pub mod cli;#[cfg(not(target_family = "wasm"))]pub mod device;