diff --git a/docs/TODO.txt b/docs/TODO.txt index f491633ee..d28add3bf 100644 --- a/docs/TODO.txt +++ b/docs/TODO.txt @@ -313,6 +313,12 @@ transfer interruption, switching under load, accessibility, and recovery from sleep or GPU reset. See flare-winui/README.md. +[ ] Qualify WinUI Serving GPU selection on a host with two CUDA GPUs. Load a + single-GPU core on GPU 1, save a different selection while serving, reload, + and verify that execution and dashboard memory move to the selected GPU. + Repeat with reordered CUDA_VISIBLE_DEVICES and different GPU architectures + to check device numbering, download selection, and compatibility filtering. + [ ] Run .github/workflows/release.yml on GitHub-hosted runners through workflow_dispatch; it has never run there. The run must establish that ubuntu-24.04-arm provides Docker for the clean-container check, that both diff --git a/flare-winui/Dashboard.inl b/flare-winui/Dashboard.inl index 8e0270c1c..148c79ab8 100644 --- a/flare-winui/Dashboard.inl +++ b/flare-winui/Dashboard.inl @@ -155,8 +155,11 @@ void update_hardware(flare_snapshot const* snapshot,flare_status const& status) { auto count=flare_snapshot_gpu_count(snapshot); flare_gpu gpu{}; - if(count&&flare_snapshot_gpu(snapshot,0,&gpu)) { - for(size_t i=0;i=0?runtime.active_gpu:runtime.gpu; + bool found=false; + for(size_t i=0;i(selected)){gpu=candidate;found=true;break;}} + if(found) { auto name=wide(gpu.name);auto annotation=name.find(L" (");if(annotation!=std::wstring::npos)name.resize(annotation); text(L"DeviceName",name);text(L"DeviceState",gpu.has_visible_ordinal?L"GPU detected":L"Not exposed to CUDA"); if(gpu.has_total_memory&&gpu.has_free_memory&&gpu.total_memory_bytes) { diff --git a/flare-winui/README.md b/flare-winui/README.md index 59cc3972b..4401198b1 100644 --- a/flare-winui/README.md +++ b/flare-winui/README.md @@ -201,7 +201,7 @@ paused, and cancelled entries remain, and downloaded data is kept for retries. Model details inspect signed metadata without granting publisher consent or loading the GPU. For this PC hides undownloaded repositories whose published -platform branches exclude the first visible GPU's platform, and local cores +platform branches exclude the selected serving GPU's platform, and local cores whose inspected requirements are known to be incompatible. Missing build metadata or an unknown GPU platform leaves a repository visible. Downloaded cores use their inspected requirements even if the repository no longer publishes a @@ -225,6 +225,7 @@ Reload model finishes accepted requests before releasing and loading the core. | Setting | Runtime behavior | |---|---| +| Serving GPU | Selects one visible NVIDIA GPU by device index, name, and total memory. Defaults to GPU 0 and respects inherited `CUDA_VISIBLE_DEVICES` numbering. Save applies the selection on the next load or reload; the dashboard continues to measure the active model's GPU until then. The desktop accepts single-GPU cores. | | Serving memory limit | `30G` caps occupied memory, `-8G` reserves free memory, and `0.8` selects a total-memory fraction per GPU. Blank inherits the configured/core reserve. KV pages use the remainder after model and runtime allocations. | | KV history capacity | One model context by default. Available memory and Context × concurrency are also selectable. The limit applies to KV history shared across requests. | | Maximum concurrent requests | Blank inherits model/configuration/core defaults. An override must fit prepared capacity. | diff --git a/flare-winui/Settings.inl b/flare-winui/Settings.inl index 9f3eadcb2..d6126019f 100644 --- a/flare-winui/Settings.inl +++ b/flare-winui/Settings.inl @@ -4,6 +4,31 @@ std::wstring runtime_prefix_directory_; double runtime_memory_gib_{2},runtime_memory_percent_{80}; int runtime_memory_mode_{}; + std::vector> runtime_gpus_; + int32_t runtime_gpu_value() { + int index=control(L"RuntimeGpu").SelectedIndex(); + return index>=0&&static_cast(index)> choices; + for(size_t i=0;i(gpu.visible_ordinal),name); + } + if(std::none_of(choices.begin(),choices.end(),[&](auto const& item){return item.first==selected;})) + choices.emplace_back(selected,L"GPU "+std::to_wstring(selected)+L" · Unavailable"); + std::sort(choices.begin(),choices.end()); + auto choice=control(L"RuntimeGpu"); + if(choices!=runtime_gpus_) { + choice.Items().Clear(); + for(auto const& item:choices)choice.Items().Append(box_value(hstring(item.second))); + runtime_gpus_=std::move(choices); + } + for(size_t i=0;i(i)); + } static std::wstring runtime_decimal(double value) { std::wostringstream output;output.imbue(std::locale::classic()); output<(name).SelectedIndex()));}; auto slider=[&](wchar_t const* name){append(runtime_decimal(control(name).Value()));}; - if(key==L"memory"){choice(L"RuntimeMemoryMode");slider(L"RuntimeMemoryValue");} + if(key==L"gpu")append(std::to_wstring(runtime_gpu_value())); + else if(key==L"memory"){choice(L"RuntimeMemoryMode");slider(L"RuntimeMemoryValue");} else if(key==L"host"){choice(L"RuntimeHostMode");append(std::wstring(control(L"RuntimeHost").Text()));} else if(key==L"port")append(runtime_decimal(control(L"RuntimePort").Value())); else if(key==L"kv")choice(L"RuntimeKvLimit"); @@ -71,7 +97,7 @@ } std::wstring runtime_form_signature() { std::wstring result; - for(auto key:{L"memory",L"host",L"port",L"kv",L"concurrency",L"verify",L"disk_enabled",L"directory",L"ram",L"disk_limit",L"age",L"drain",L"storage",L"embedding",L"drafts",L"adaptive"}){ + for(auto key:{L"gpu",L"memory",L"host",L"port",L"kv",L"concurrency",L"verify",L"disk_enabled",L"directory",L"ram",L"disk_limit",L"age",L"drain",L"storage",L"embedding",L"drafts",L"adaptive"}){ auto value=runtime_field_signature(key);result+=std::to_wstring(value.size())+L":"+value; } return result; @@ -85,6 +111,7 @@ return selected==0?L"":selected==1?L"0":runtime_decimal(control(slider).Value())+L"GiB"; } void initialize_runtime_settings() { + control(L"RuntimeGpu").SelectionChanged([this](auto const&,auto const&){runtime_settings_changed();}); clicked(L"RuntimeSettingsSave",[this]{save_runtime_settings();}); clicked(L"RuntimeSettingsReload",[this]{for(auto const& model:models_)if(!model.catalog()&&(model.flags&FLARE_MODEL_ACTIVE)){activate(model.id,model.name,true);break;}}); clicked(L"RuntimeSettingsRevert",[this]{runtime_settings_dirty_=false;runtime_settings_initialized_=false;runtime_settings_error_.clear();poll();}); @@ -110,6 +137,7 @@ control(L"RuntimeHost").Visibility(host==2?Visibility::Visible:Visibility::Collapsed); text(L"RuntimeNetworkNote",host==1?L"Available to your network. Windows firewall rules apply.":host==2?L"Use an IPv4 or IPv6 address assigned to this PC.":L"Only applications on this PC can connect."); bool editing=runtime_settings_operation_==0; + control(L"RuntimeGpu").IsEnabled(editing); for(auto name:{L"RuntimeMemoryMode",L"RuntimeMemoryValue",L"RuntimeHost",L"RuntimeHostMode",L"RuntimeKvLimit",L"RuntimeConcurrencyAuto",L"RuntimeVerify",L"RuntimePort",L"RuntimePrefixDiskEnabled",L"RuntimePrefixMemoryMode",L"RuntimePrefixMaxAge",L"RuntimeDraftMode",L"RuntimeAdaptiveVerification",L"RuntimeEmbeddingStorage",L"RuntimeEmbeddingCacheMode"})control(name).IsEnabled(editing); bool disk=control(L"RuntimePrefixDiskEnabled").IsOn(); for(auto name:{L"RuntimePrefixBrowse",L"RuntimePrefixDiskLimitMode",L"RuntimePrefixDrain"})control(name).IsEnabled(disk&&editing); @@ -139,6 +167,9 @@ } void update_runtime_settings(flare_snapshot const* snapshot,flare_status const& status) { flare_runtime_settings value{};if(!flare_snapshot_runtime_settings(snapshot,&value))return; + if(runtime_settings_initialized_&&runtime_original_[L"gpu"]!=std::to_wstring(value.gpu)) { + compatibilities_.clear();catalog_requested_=false;model_fingerprint_.clear(); + } runtime_settings_busy_=status.busy!=0;runtime_reload_pending_=value.pending_reload!=0; if(runtime_settings_operation_&&value.last_settings_operation==runtime_settings_operation_) { runtime_settings_operation_=0;runtime_settings_error_=wide(value.settings_error); @@ -147,12 +178,14 @@ if(!runtime_settings_initialized_||(!runtime_settings_dirty_&&!runtime_settings_operation_)) { struct ApplyingReset {bool& value;~ApplyingReset(){value=false;}} applying_reset{runtime_settings_applying_}; runtime_settings_applying_=true; + runtime_gpu_choices(snapshot,value.gpu); runtime_original_={{L"memory",wide(value.memory_limit)},{L"host",wide(value.host)},{L"kv",wide(value.kv_cache_limit)}, {L"ram",wide(value.prefix_cache_memory)},{L"directory",wide(value.prefix_cache_disk)},{L"disk_limit",wide(value.prefix_cache_disk_limit)}, {L"age",wide(value.prefix_cache_max_age)},{L"drain",wide(value.prefix_cache_drain_on_shutdown)}, {L"storage",wide(value.embedding_table_storage)},{L"embedding",wide(value.embedding_table_cache_size)}, {L"concurrency",value.has_max_concurrency?std::to_wstring(value.max_concurrency):L""}, - {L"drafts",value.has_mtp_draft_tokens?std::to_wstring(value.mtp_draft_tokens):L""}}; + {L"drafts",value.has_mtp_draft_tokens?std::to_wstring(value.mtp_draft_tokens):L""}, + {L"gpu",std::to_wstring(value.gpu)}}; auto host=runtime_original_[L"host"]; control(L"RuntimeHost").Text(host); control(L"RuntimeHostMode").SelectedIndex(host==L"127.0.0.1"?0:host==L"0.0.0.0"?1:2); @@ -200,6 +233,7 @@ std::vector strings;strings.reserve(16); auto store=[&](std::wstring raw){strings.push_back(to_string(hstring(raw)));auto const& s=strings.back();return flare_string{s.data(),s.size()};}; flare_runtime_settings value{}; + value.gpu=runtime_gpu_value(); int memory=control(L"RuntimeMemoryMode").SelectedIndex(); double amount=control(L"RuntimeMemoryValue").Value(); auto memoryText=memory==0?L"":memory==3?runtime_decimal(amount/100):std::wstring(memory==2?L"-":L"")+runtime_decimal(amount)+L"GiB"; diff --git a/flare-winui/Shell.xaml.h b/flare-winui/Shell.xaml.h index 5959e0e5e..fe175a712 100644 --- a/flare-winui/Shell.xaml.h +++ b/flare-winui/Shell.xaml.h @@ -90,6 +90,7 @@ LR"xaml( + diff --git a/flare-winui/bridge/include/flare.h b/flare-winui/bridge/include/flare.h index a1439895b..8fffee35e 100644 --- a/flare-winui/bridge/include/flare.h +++ b/flare-winui/bridge/include/flare.h @@ -92,6 +92,7 @@ typedef struct flare_dashboard_point { core defaults. Optional booleans: 0 inherit, 1 off, 2 on. Read-only output fields are ignored on input; authentication secrets are never returned. */ typedef struct flare_runtime_settings { + int32_t gpu, active_gpu; /* Visible device index; active_gpu is -1 when stopped. */ flare_string memory_limit, kv_cache_limit, host; flare_string prefix_cache_memory, prefix_cache_disk, prefix_cache_disk_limit; flare_string embedding_table_storage, embedding_table_cache_size; diff --git a/flare-winui/bridge/src/lib.rs b/flare-winui/bridge/src/lib.rs index 1bcbcb721..a65dcbb25 100644 --- a/flare-winui/bridge/src/lib.rs +++ b/flare-winui/bridge/src/lib.rs @@ -1423,6 +1423,8 @@ mod dashboard_tests { #[repr(C)] pub struct FlareRuntimeSettings { + gpu: i32, + active_gpu: i32, memory_limit: FlareString, kv_cache_limit: FlareString, host: FlareString, @@ -1484,6 +1486,7 @@ unsafe fn runtime_input( } }; Ok(flare::settings::RuntimeSettings { + gpu: s.gpu, memory_limit: copy(s.memory_limit)?, kv_cache_limit: copy(s.kv_cache_limit)?, host: copy(s.host)?, @@ -1527,6 +1530,8 @@ pub unsafe extern "C" fn flare_snapshot_runtime_settings( output( out, FlareRuntimeSettings { + gpu: s.gpu, + active_gpu: view.active_gpu.unwrap_or(-1), memory_limit: text(&s.memory_limit), kv_cache_limit: text(&s.kv_cache_limit), host: text(&s.host), @@ -1562,6 +1567,7 @@ mod runtime_settings_abi_tests { #[test] fn runtime_settings_abi_copies_options_and_borrows_only_snapshot_output() { let mut view=Snapshot::default(); + view.runtime_settings.gpu=2;view.active_gpu=Some(1); view.runtime_settings.max_concurrency=Some(3);view.runtime_settings.mtp_draft_tokens=Some(0); view.runtime_settings.adaptive_verification=Some(true); view.runtime_settings.prefix_cache_disk="C:/模型/prefix-cache".into(); @@ -1572,6 +1578,7 @@ mod runtime_settings_abi_tests { let mut out=std::mem::MaybeUninit::::uninit(); assert_eq!(flare_snapshot_runtime_settings(held,out.as_mut_ptr()),1); let mut found=out.assume_init(); + assert_eq!((found.gpu,found.active_gpu),(2,1)); assert_eq!((found.has_max_concurrency,found.max_concurrency,found.has_mtp_draft_tokens,found.mtp_draft_tokens),(1,3,1,0)); assert_eq!((found.adaptive_verification,found.pending_reload,found.has_api_key,found.prefix_cache_disk_enabled),(2,1,1,0)); assert_eq!(found.last_settings_operation,42); diff --git a/flare/src/controller.rs b/flare/src/controller.rs index 7c44e012f..bd26bc59b 100644 --- a/flare/src/controller.rs +++ b/flare/src/controller.rs @@ -187,6 +187,7 @@ pub struct Snapshot { pub model_update_check: Option, pub runtime_settings: RuntimeSettings, pub runtime_settings_pending_reload: bool, + pub active_gpu: Option, pub has_api_key: bool, pub last_settings_operation: u64, pub settings_error: String, @@ -1003,6 +1004,7 @@ impl Controller { let dashboard = self.shared.dashboard.lock().unwrap_or_else(|e| e.into_inner()).sample(&sample); let bind = active.session.server().address(); view.bind_address = bind.to_string(); + view.active_gpu = Some(active.runtime.gpu); ( sample, active.name.clone(), @@ -1263,7 +1265,7 @@ impl Worker { .map_err(|e| e.to_string())?.1.is_none() { options.revision = Some( - crate::hardware::detect(1) + crate::hardware::detect_devices(&[job.settings.runtime.gpu]) .map_err(|e| e.to_string())? .into(), ); @@ -1485,6 +1487,7 @@ impl Worker { runtime.validate()?; let mut desired = self.settings.clone(); desired.runtime = runtime.clone(); + let gpu_changed = runtime.gpu != self.settings.runtime.gpu; let pending = if let Some(active) = &self.active { let names: Vec<_> = active.model_names.iter().map(String::as_str).collect(); desired.runtime_identity(&names).map_err(|e| e.to_string())? != active.runtime @@ -1497,7 +1500,14 @@ impl Worker { self.shared.update(|s| { s.view.runtime_settings = runtime; s.view.runtime_settings_pending_reload = pending; + if gpu_changed { + s.view.model_detail = None; + s.view.models.retain(|model| model.flags & 16 == 0); + } }); + if gpu_changed { + self.catalog.clear(); + } Ok(()) } Command::Refresh => { @@ -1512,7 +1522,7 @@ impl Worker { Command::LocateReference { id, path } => self.locate_reference(&id, path), Command::Discover(query) => { self.shared.update(|s| s.view.catalog_loading = true); - let hardware = crate::hardware::detect(1).ok(); + let hardware = crate::hardware::detect_devices(&[self.settings.runtime.gpu]).ok(); let result = crate::catalog::search_for_hardware(&query, hardware) .map_err(|e| e.to_string()); self.shared.update(|s| s.view.catalog_loading = false); @@ -2801,6 +2811,12 @@ impl Worker { ); } let names = authorized.core.model_names().map_err(|e| e.to_string())?; + let gpu = self.settings.runtime.gpu; + if !crate::hardware::inventory().map_err(|e| e.to_string())?.iter() + .any(|device| device.visible_ordinal == Some(gpu as u32)) + { + return Err(format!("Serving GPU {gpu} is unavailable; choose a visible GPU in Settings")); + } let options = self .settings .load_options(&names) @@ -2867,7 +2883,7 @@ impl Worker { // SAFETY: Publisher consent authorizes running a trusted prepared core. // Its programs must obey the loader's CUDA contract; signatures do not // establish memory safety. The owned session retains resources through drain. - let owner = match unsafe { NativeModel::load(core, &[0], &options, &progress) } { + let owner = match unsafe { NativeModel::load(core, &[runtime.gpu], &options, &progress) } { Ok(owner) => owner, Err(error) => { // The loader does not return drain evidence. Keep the core @@ -3331,7 +3347,7 @@ impl Worker { }, id.into(), model.name.clone(), - &gpus, + gpus.iter().find(|gpu| gpu.visible_ordinal == Some(self.settings.runtime.gpu as u32)), ) .map_err(|error| error.to_string()) })(); @@ -3345,7 +3361,8 @@ impl Worker { ..Default::default() }); detail.can_remove_reference = matches!(source, Some(Source::LocalPath(_))) && !active; - if active && matches!(source, Some(Source::LocalModel { .. })) && detail.signatures_verified + if active && self.active.as_ref().is_some_and(|session| session.runtime.gpu == self.settings.runtime.gpu) + && matches!(source, Some(Source::LocalModel { .. })) && detail.signatures_verified { detail.compatibility = Compatibility::Compatible; detail.compatibility_reason = "This core is serving in this process.".into(); @@ -3441,6 +3458,8 @@ mod runtime_settings_tests { std::fs::write(config.with_file_name("desktop-state.json"),r#"{"unrelated_state":{"keep":7}}"#).unwrap(); let app=Controller::new(Some(config.clone())).unwrap(); let mut desired=app.snapshot().runtime_settings; + assert_eq!(desired.gpu, 0); + desired.gpu = 1; assert!(!desired.verify_weights);assert!(!desired.prefix_cache_disk_enabled); assert_eq!(desired.kv_cache_limit, "context"); desired.kv_cache_limit = "memory".into(); @@ -3467,6 +3486,12 @@ mod runtime_settings_tests { assert_eq!(ready.state,SessionState::Ready); assert_eq!(ready.error,"Keep runtime error"); assert_eq!(ready.runtime_settings,desired); + let mut invalid = desired.clone(); + invalid.gpu = -1; + let operation = app.submit(Command::SetRuntimeSettings(invalid)).unwrap(); + let rejected = wait_settings(&app, operation); + assert!(!rejected.settings_error.is_empty()); + assert_eq!(rejected.runtime_settings, desired); close(&app);drop(app); let restored=Controller::new(Some(config)).unwrap(); assert_eq!(restored.snapshot().runtime_settings,desired);assert!(restored.snapshot().has_api_key); diff --git a/flare/src/details.rs b/flare/src/details.rs index c751198cc..c2a888265 100644 --- a/flare/src/details.rs +++ b/flare/src/details.rs @@ -41,7 +41,7 @@ pub fn inspect( options: &TrustOptions, id: String, name: String, - gpus: &[GpuInfo], + gpu: Option<&GpuInfo>, ) -> crate::application::Result { let resolved = store.resolve(source)?; let mut detail=ModelDetailView { id,name,path:resolved.path.display().to_string(), @@ -104,11 +104,11 @@ pub fn inspect( } } } - populate(&mut detail, &document, gpus); + populate(&mut detail, &document, gpu); Ok(detail) } -fn populate(detail: &mut ModelDetailView, document: &Value, gpus: &[GpuInfo]) { +fn populate(detail: &mut ModelDetailView, document: &Value, gpu: Option<&GpuInfo>) { detail.context_tokens = document["model"]["max_sequence_tokens"] .as_u64() .filter(|value| *value > 0); @@ -175,7 +175,7 @@ fn populate(detail: &mut ModelDetailView, document: &Value, gpus: &[GpuInfo]) { detail.compatibility = Compatibility::Incompatible; detail.compatibility_reason = "The desktop runtime requires a core prepared for one local GPU.".into(); - } else if let Some(gpu) = gpus.iter().find(|gpu| gpu.visible_ordinal == Some(0)) { + } else if let Some(gpu) = gpu { if let Some(actual) = gpu.architecture { if !architectures.is_empty() && !architectures.contains(&actual) { detail.compatibility = Compatibility::Incompatible; @@ -212,12 +212,12 @@ mod tests { &mut detail, &json!({"model":{"max_sequence_tokens":8192,"max_active":4},"rank_count":1, "ranks":[{"architecture":[12,0],"allocations":[{"nbytes":1024}]}]}), - &[GpuInfo { + Some(&GpuInfo { visible_ordinal: Some(0), architecture: Some([12, 0]), total_memory_bytes: Some(2048), ..Default::default() - }], + }), ); assert_eq!(detail.context_tokens, Some(8192)); assert_eq!(detail.prepared_memory_bytes, Some(1024)); @@ -233,11 +233,11 @@ mod tests { populate( &mut detail, &json!({"rank_count":1,"ranks":[{"architecture":[12,0]}]}), - &[GpuInfo { - visible_ordinal: Some(0), + Some(&GpuInfo { + visible_ordinal: Some(1), architecture: Some([10, 3]), ..Default::default() - }], + }), ); assert_eq!(detail.compatibility, Compatibility::Incompatible); assert!(detail.compatibility_reason.contains("SM103")); @@ -263,7 +263,7 @@ mod tests { }, "fixture".into(), "Fixture".into(), - &[], + None, ) .unwrap(); assert!(result.signatures_verified); diff --git a/flare/src/hardware.rs b/flare/src/hardware.rs index 881a1bd01..d45f3bfae 100644 --- a/flare/src/hardware.rs +++ b/flare/src/hardware.rs @@ -25,9 +25,13 @@ fn platform_from_capability(major: u32, minor: u32) -> Option<&'static str> { } pub fn detect(count: usize) -> Result<&'static str> { - let inherited = std::env::var("CUDA_VISIBLE_DEVICES").ok(); let indices: Vec<_> = (0..count as i32).collect(); - let visible = crate::environment::visibility(&indices, inherited.as_deref())?; + detect_devices(&indices) +} + +pub fn detect_devices(indices: &[i32]) -> Result<&'static str> { + let inherited = std::env::var("CUDA_VISIBLE_DEVICES").ok(); + let visible = crate::environment::visibility(indices, inherited.as_deref())?; let nvml = Nvml::load().map_err(|error| { format!("cannot detect hardware without NVIDIA NVML: {error}; specify --revision") })?; diff --git a/flare/src/runtime_settings.rs b/flare/src/runtime_settings.rs index 6831afc90..81b811f6b 100644 --- a/flare/src/runtime_settings.rs +++ b/flare/src/runtime_settings.rs @@ -13,6 +13,7 @@ use std::{ #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(default)] pub struct RuntimeSettings { + pub gpu: i32, pub memory_limit: String, pub kv_cache_limit: String, pub host: String, @@ -33,6 +34,7 @@ pub struct RuntimeSettings { impl Default for RuntimeSettings { fn default() -> Self { Self { + gpu: 0, memory_limit: String::new(), kv_cache_limit: "context".into(), host: "127.0.0.1".into(), @@ -76,6 +78,9 @@ impl RuntimeSettings { mut base: LoadOptions, default_disk: PathBuf, ) -> Result { + if self.gpu < 0 { + return Err("Serving GPU must be a nonnegative visible device index".into()); + } self.bind()?; for (name, value) in [ ("memory limit", &self.memory_limit), @@ -156,6 +161,7 @@ fn budget(value: &str, name: &str) -> Result, String> { } #[derive(Clone, Debug, PartialEq)] pub(crate) struct RuntimeIdentity { + pub(crate) gpu: i32, bind: SocketAddr, verify_weights: bool, kv_cache_limit: KvCacheLimit, @@ -170,6 +176,7 @@ pub(crate) struct RuntimeIdentity { impl RuntimeIdentity { pub(crate) fn new(runtime: &RuntimeSettings, options: &LoadOptions) -> Result { Ok(Self { + gpu: runtime.gpu, bind: runtime.bind()?, verify_weights: runtime.verify_weights, kv_cache_limit: options.kv_cache_limit, @@ -188,6 +195,18 @@ impl RuntimeIdentity { mod tests { use super::*; #[test] + fn gpu_selection_defaults_to_zero_and_changes_runtime_identity() { + let mut runtime: RuntimeSettings = serde_json::from_str("{}").unwrap(); + assert_eq!(runtime.gpu, 0); + let options = LoadOptions::default(); + let initial = RuntimeIdentity::new(&runtime, &options).unwrap(); + runtime.gpu = 1; + runtime.validate().unwrap(); + assert_ne!(initial, RuntimeIdentity::new(&runtime, &options).unwrap()); + runtime.gpu = -1; + assert!(runtime.validate().is_err()); + } + #[test] fn desktop_defaults_apply_one_context_and_disable_disk_and_weight_verification() { let runtime = RuntimeSettings::default(); let options = runtime