mirror of
https://github.com/hanzoai/ml.git
synced 2026-11-20 23:08:29 +00:00
Three-way per file through the rename: base 39355c6c91, theirs the upstream
merge of main with 35d7ae7c (via 7ef6a694d), ours origin/main.
Lands the barrier thread pool, runtime CPU feature dispatch, aarch64 and x86
repacked quantized kernels (indexed_gemv, gemv_fused_shared_lhs), quantized
embedding on CPU/Metal/CUDA, paged flash-attn kernels, cutile fused MoE, the
in-place op aliasing API, parking_lot storage locks, Metal buffer builders and
debug labels, safetensors 0.8, hf-hub 1.0, tokenizers 0.23.
Ours keeps ROCm, Vulkan, wgpu, the IQ/MXFP4/NVFP4/TQ dtypes, and the i-quant
weight/activation block split in matmul. Our backends ride InplaceOpN and the
quantized embedding; Metal get_rows gains the IQ kernels. ug leaves, as upstream.
Co-authored-by: Hanzo Dev <[email protected]>
52 lines
1.8 KiB
Rust
52 lines
1.8 KiB
Rust
#![allow(unused)]
|
|
#[cfg(feature = "buildtime-download")]
|
|
mod buildtime_downloader;
|
|
|
|
struct KernelDirectories {
|
|
kernel_glob: &'static str,
|
|
rust_target: &'static str,
|
|
}
|
|
|
|
const KERNEL_DIRS: [KernelDirectories; 1] = [KernelDirectories {
|
|
kernel_glob: "examples/custom-ops/kernels/*.cu",
|
|
rust_target: "examples/custom-ops/cuda_kernels.rs",
|
|
}];
|
|
|
|
fn main() {
|
|
println!("cargo::rerun-if-changed=build.rs");
|
|
|
|
#[cfg(feature = "cuda")]
|
|
{
|
|
use std::env;
|
|
use std::path::{Path, PathBuf};
|
|
// Added: Get the safe output directory from the environment.
|
|
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
|
|
|
for kdir in KERNEL_DIRS.iter() {
|
|
// Changed: This now writes to a safe path inside $OUT_DIR.
|
|
let safe_target = out_dir.join(
|
|
Path::new(kdir.rust_target)
|
|
.file_name()
|
|
.expect("Failed to get filename from rust_target"),
|
|
);
|
|
|
|
let bindings = cudaforge::KernelBuilder::new()
|
|
.source_glob(kdir.kernel_glob)
|
|
.build_ptx()
|
|
.expect("Failed to build ptx");
|
|
bindings
|
|
.write(safe_target)
|
|
.expect("Failed to write ptx bindings");
|
|
}
|
|
}
|
|
|
|
// Download config, tokenizer, and model files from hf at build time.
|
|
// option_env! automatically detects changes in the env var and trigger rebuilds correctly.
|
|
// Example value:
|
|
// BUILDTIME_MODEL_REVISION="sentence-transformers/all-MiniLM-L6-v2:c9745ed1d9f207416be6d2e6f8de32d1f16199bf"
|
|
#[cfg(feature = "buildtime-download")]
|
|
if let Some(model_rev) = core::option_env!("BUILDTIME_MODEL_REVISION") {
|
|
buildtime_downloader::download_model(model_rev).expect("Model download failed!");
|
|
}
|
|
}
|