Implement Qwen text core

This commit is contained in:
Georg Bauer committed 2026-09-03 20:31:53 +02:00
1 parent 3773cfda2e
commit c414640050
9 files changed
+2766 -52

No files matched your search

+2
View File
@@ -320,6 +320,7 @@ impl Executor {
match self {
Self::DeepSeek(executor) => executor.save_checkpoint(path, tag, progress),
Self::Glm(executor) => executor.save_checkpoint(path, tag, progress),
Self::Qwen(executor) => executor.save_checkpoint(path, tag, progress),
}
}
@@ -331,6 +332,7 @@ impl Executor {
match self {
Self::DeepSeek(executor) => executor.load_checkpoint(path, progress),
Self::Glm(executor) => executor.load_checkpoint(path, progress),
Self::Qwen(executor) => executor.load_checkpoint(path, progress),
}
}
}
+50 -2
View File
@@ -5,6 +5,22 @@ pub(super) struct GpuTensor {
_private: [u8; 0],
}
#[derive(Clone, Copy)]
#[repr(C)]
pub(super) struct QwenWeightView {
pub(super) map: *const c_void,
pub(super) size: u64,
pub(super) offset: u64,
pub(super) bytes: u64,
}
#[derive(Clone, Copy, Default)]
#[repr(C)]
pub(super) struct QwenKernelArgs {
pub(super) u: [u32; 16],
pub(super) f: [f32; 8],
}
#[derive(Clone, Copy, Default)]
#[repr(C)]
pub(super) struct Glm53VisionLayerWeights {
@@ -81,6 +97,18 @@ unsafe extern "C" {
map_size: u64,
max_tensor_bytes: u64,
) -> i32;
pub(super) fn ds4_gpu_qwen_dispatch(
kernel: *const c_char,
out: *mut GpuTensor,
a: *const GpuTensor,
b: *const GpuTensor,
c: *const GpuTensor,
weights: *const QwenWeightView,
weight_count: u32,
args: *const QwenKernelArgs,
grid_x: u32,
grid_y: u32,
) -> i32;
pub(super) fn ds4_gpu_set_transient_model_map_range(
model_map: *const c_void,
model_size: u64,
@@ -1804,7 +1832,7 @@ unsafe extern "C" {
}
pub(super) struct Context {
_model_file: File,
_model_file: Option<File>,
}
impl Context {
@@ -1908,9 +1936,29 @@ impl Context {
}
}
Ok(Self {
_model_file: model_file,
_model_file: Some(model_file),
})
}
pub(super) fn open_qwen(admission_bytes: u64) -> Result<Self, String> {
check(unsafe { ds4_gpu_init() }, "Metal initialization")?;
unsafe {
ds4_gpu_set_glm_model(false);
ds4_gpu_set_ssd_streaming(false);
ds4_gpu_set_decode_pipeline_fast_lookup(0);
}
let recommended = unsafe { ds4_gpu_recommended_working_set_size() };
if admission_bytes != 0 && recommended != 0 && admission_bytes > recommended {
unsafe { ds4_gpu_cleanup() };
return Err(format!(
"Qwen model load needs {:.1} GiB including context and scratch, but Metal recommends at most {:.1} GiB",
admission_bytes as f64 / 1_073_741_824.0,
recommended as f64 / 1_073_741_824.0,
));
}
unsafe { ds4_gpu_set_quality(true) };
Ok(Self { _model_file: None })
}
}
impl Drop for Context {
File diff suppressed because it is too large. Load diff