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.

3.0.8 fixes: refusal removal runs on Windows (UTF-8 under isolated Python), download progress from the hub's own byte count

purple5936e1ec11e8
diff --git a/src-tauri/resources/abliterate/lu_abliterate.py b/src-tauri/resources/abliterate/lu_abliterate.py
index 37ce2c65..47b8ce27 100644
--- a/src-tauri/resources/abliterate/lu_abliterate.py
+++ b/src-tauri/resources/abliterate/lu_abliterate.py
@@ -27,6 +27,16 @@ import time
from pathlib import Path
+# The app starts Python isolated (-I), which ignores PYTHONIOENCODING and
+# PYTHONUTF8. On Windows a pipe is then cp1252, and Heretic's banner (block
+# characters) killed the search with UnicodeEncodeError on the box.
+for _stream in (sys.stdout, sys.stderr):
+ try:
+ _stream.reconfigure(encoding="utf-8", errors="replace")
+ except (AttributeError, ValueError):
+ pass
+
+
def emit(event, **fields):
fields["event"] = event
sys.stdout.write("@lu " + json.dumps(fields) + "\n")
@@ -68,6 +78,33 @@ WEIGHT_PATTERNS = [
]
+def byte_progress_class():
+ """A tqdm class for snapshot_download that reports bytes instead of
+ drawing a bar. huggingface_hub 1.x always downloads through Xet, which
+ keeps a file in memory and writes it at the end, so the folder size the
+ app used to read stood at zero until the download was over."""
+ from tqdm import tqdm
+
+ class ByteProgress(tqdm):
+ def __init__(self, *args, **kwargs):
+ kwargs.pop("name", None)
+ kwargs["disable"] = False
+ kwargs["file"] = open(os.devnull, "w")
+ super().__init__(*args, **kwargs)
+ self._said = 0.0
+
+ def update(self, n=1):
+ out = super().update(n)
+ if (self.desc or "").startswith("Downloading bytes"):
+ now = time.time()
+ if now - self._said >= 1.0 or (self.total and self.n >= self.total):
+ self._said = now
+ emit("bytes", done=int(self.n), total=int(self.total or 0))
+ return out
+
+ return ByteProgress
+
+
def cmd_download(a):
from huggingface_hub import snapshot_download
@@ -80,6 +117,7 @@ def cmd_download(a):
local_dir=a.dest,
allow_patterns=WEIGHT_PATTERNS,
ignore_patterns=["*.bin", "*.pt", "*.pth", "*.gguf", "original/*", "consolidated*"],
+ tqdm_class=byte_progress_class(),
)
emit("downloaded", path=str(path))
diff --git a/src-tauri/src/commands/abliterate/mod.rs b/src-tauri/src/commands/abliterate/mod.rs
index cf8977d0..216c8002 100644
--- a/src-tauri/src/commands/abliterate/mod.rs
+++ b/src-tauri/src/commands/abliterate/mod.rs
@@ -864,9 +864,17 @@ fn run_job(app: &tauri::AppHandle, job: &Job) -> Result<RunRecord, String> {
.args(["download", "--repo", &job.repo, "--revision", &job.revision, "--dest"])
.arg(&source_dir);
let watcher = watch_size(dir);
- let result = run_python(cmd, "download", |_| {});
+ // The bytes the hub reports; the folder size alone stays at zero
+ // while Xet holds a file in memory.
+ let result = run_python(cmd, "download", |ev| {
+ if ev.get("event").and_then(|e| e.as_str()) == Some("bytes") {
+ let done = ev.get("done").and_then(|v| v.as_u64()).unwrap_or(0);
+ with_run(|r| r.step = r.step.max(done));
+ }
+ });
watcher.store(false, Ordering::SeqCst);
result?;
+ with_run(|r| r.step = r.total);
}
check_cancel()?;
@@ -969,7 +977,7 @@ fn run_job(app: &tauri::AppHandle, job: &Job) -> Result<RunRecord, String> {
let converted = if quantize_to.is_some() { job.work.join("converted-bf16.gguf") } else { partial.clone() };
set_phase("convert", "Converting to GGUF");
let mut cmd = crate::python::python_command(&py);
- cmd.env_remove("PYTHONHOME").env_remove("PYTHONPATH").arg("-s").arg("-E");
+ cmd.env_remove("PYTHONHOME").env_remove("PYTHONPATH").args(["-s", "-E", "-X", "utf8"]);
cmd.arg(convert_dir().join("convert_hf_to_gguf.py"))
.arg(&merged)
.args(["--outtype", convert_type, "--outfile"])
@@ -1110,15 +1118,15 @@ fn on_search_event(ev: &Value, job: &Job, picked: &mut Option<Picked>) {
/// The venv's Python with the environment every step shares.
fn python(py: &Path, job: &Job) -> Command {
let mut cmd = crate::python::python_command(py);
- cmd.env_remove("PYTHONHOME").env_remove("PYTHONPATH").arg("-I");
+ // -I ignores every PYTHON* variable, PYTHONUTF8 and PYTHONIOENCODING
+ // included, so UTF-8 goes on the command line (a Windows pipe is cp1252
+ // otherwise) and -u stands in for PYTHONUNBUFFERED.
+ cmd.env_remove("PYTHONHOME").env_remove("PYTHONPATH").args(["-I", "-X", "utf8", "-u"]);
cmd.env("PYTHONUNBUFFERED", "1")
.env("TOKENIZERS_PARALLELISM", "false")
.env("HF_HUB_DISABLE_TELEMETRY", "1")
.env("HF_HUB_DISABLE_PROGRESS_BARS", "1")
- // The Xet path holds a file in memory and writes it at the end, so
- // the folder size the progress bar reads stood still for minutes.
- // The plain download writes as it goes.
- .env("HF_HUB_DISABLE_XET", "1")
+
.env("HF_HOME", root().join("hf"))
.env("PYTORCH_ENABLE_MPS_FALLBACK", "1")
.current_dir(&job.work);
@@ -1253,7 +1261,7 @@ fn watch_size(dir: PathBuf) -> Arc<AtomicBool> {
std::thread::spawn(move || {
while flag.load(Ordering::SeqCst) {
let size = dir_size(&dir);
- with_run(|r| r.step = size.min(r.total.max(size)));
+ with_run(|r| r.step = r.step.max(size));
std::thread::sleep(Duration::from_millis(800));
}
});