Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(video): give the MLX-video Xet cache HF_HOME instead of the system default

purple8f92f06be4c4
diff --git a/src-tauri/src/commands/video.rs b/src-tauri/src/commands/video.rs
index 9224aa98..cc8c39c5 100644
--- a/src-tauri/src/commands/video.rs
+++ b/src-tauri/src/commands/video.rs
@@ -193,6 +193,18 @@ fn model_dir(id: &str) -> PathBuf {
models_root().join(id)
}
+/// K5: `huggingface_hub`'s Xet chunk cache ignores `local_dir` — it only
+/// follows `HF_HOME` (and, since `hf_xet` split out of the main package,
+/// `HF_XET_CACHE`). Without either set, it falls back to
+/// `~/.cache/huggingface[/xet]`, on the SYSTEM drive, regardless of which
+/// drive `models_root()` was pointed at. `commands::mlx.rs` already gets
+/// this right (`.env("HF_HOME", mlx_root().join("cache"))` at every
+/// `snapshot_download`/`hf_hub_download` call); this is the same fix for the
+/// one call site in this file that was missing it.
+fn hf_home_dir() -> PathBuf {
+ models_root().join(".hf-cache")
+}
+
/// Directory the generate CLI actually points at: the converted MLX weights
/// for wan_2 (`<id>/mlx`), the pre-converted download itself for ltx_2.
fn weights_dir(entry: &CatalogEntry) -> PathBuf {
@@ -464,8 +476,8 @@ pub fn video_install_model(state: &AppState, args: &Value) -> CmdResult {
// Kein geteilter Zwischenspeicher: dieser Weg laedt mit `local_dir`, und
// huggingface_hub legt den Zwischenstand dann unter `<local_dir>/.cache`
// ab, also INNERHALB des Ordners, der hier gemessen wird. Der Xet-Cache
- // liegt fuer diesen Weg trotzdem daneben (HF_HOME wird hier nicht gesetzt,
- // also im Standardordner des Nutzers); siehe Bericht bauer-t, Fund 3.
+ // liegt seit K5 ebenfalls darunter (`hf_home_dir()` unter `models_root()`),
+ // nicht mehr im Standardordner des Nutzers auf dem Systemlaufwerk.
crate::install_state::watch_dir_size(
slot.clone(),
model_dir(entry.id),
@@ -521,7 +533,9 @@ fn install_model_steps(
t = download_to.to_string_lossy(),
);
let mut cmd = Command::new(python);
- cmd.args(["-c", &script]);
+ cmd.args(["-c", &script])
+ .env("HF_HOME", hf_home_dir())
+ .env("HF_XET_CACHE", hf_home_dir().join("xet"));
crate::commands::mlx::apply_hf_token(&mut cmd);
run_streamed(slot, &mut cmd)?;
@@ -863,6 +877,46 @@ fn exit_reason(status: &std::process::ExitStatus) -> String {
mod tests {
use super::*;
+ #[test]
+ fn hf_home_dir_lives_under_models_root_not_the_user_cache() {
+ // K5: the Xet chunk cache must follow whichever drive
+ // `models_root()` resolves to, not fall back to the OS-default
+ // `~/.cache/huggingface` on the system drive.
+ assert!(hf_home_dir().starts_with(models_root()), "{:?}", hf_home_dir());
+ assert_eq!(hf_home_dir().file_name().unwrap(), ".hf-cache");
+ }
+
+ #[test]
+ fn the_snapshot_download_call_sets_hf_home_and_xet_cache() {
+ // K5 (Discord x_guestieco_x, 13.09.: "everytime I try to force the
+ // app to go to my E drive it always takes up space on my C
+ // drive"). huggingface_hub's Xet chunk cache ignores `local_dir`
+ // and only follows HF_HOME/HF_XET_CACHE — without them it fills the
+ // SYSTEM drive's default cache regardless of where models_root()
+ // points. `commands::mlx.rs` already sets both on every
+ // snapshot_download/hf_hub_download call; this proves this file's
+ // one call site does too.
+ let src = include_str!("video.rs");
+ let start = src.find("fn install_model_steps(").expect("install_model_steps is gone");
+ let end = src[start..]
+ .find("\npub fn video_install_model_status")
+ .map(|i| start + i)
+ .unwrap_or(src.len());
+ let body = &src[start..end];
+ assert!(
+ body.contains("from huggingface_hub import snapshot_download"),
+ "the download call itself moved"
+ );
+ assert!(
+ body.contains(".env(\"HF_HOME\", hf_home_dir())"),
+ "HF_HOME is no longer set on the snapshot_download command"
+ );
+ assert!(
+ body.contains(".env(\"HF_XET_CACHE\", hf_home_dir().join(\"xet\"))"),
+ "HF_XET_CACHE is no longer set on the snapshot_download command"
+ );
+ }
+
/// "command exited None" war die Meldung nach einem abgebrochenen
/// MLX-Download (bauer-m N4). Siehe den Kopf von `exit_reason`.
// Der Rohstatus mit einem Signal darin gibt es nur unter Unix; auf Windows