Skip to content

fix(provider): resolve FLUX.2 Klein pipeline by s3_name, not legacy cache path#51

Open
lukevenediger wants to merge 1 commit intoLayr-Labs:masterfrom
lukevenediger:fix/image-model-download-path-match
Open

fix(provider): resolve FLUX.2 Klein pipeline by s3_name, not legacy cache path#51
lukevenediger wants to merge 1 commit intoLayr-Labs:masterfrom
lukevenediger:fix/image-model-download-path-match

Conversation

@lukevenediger
Copy link
Copy Markdown

Summary

  • download_ckpt_model_from_cdn matched the FLUX.2 Klein pipeline against cache_dir.contains("flux_2_klein_{4,9}b_q8p"), but cmd_models writes image models to ~/.darkbloom/models/<s3_name> (e.g. flux-klein-4b-q8). The match always fell through to the None arm, so users saw ⚠ Unknown image model after the tarball fallback 404'd.
  • Match on a combined key of base_url (carries s3_name) and cache_dir, accepting both dashed (klein-4b/klein-9b) and underscored (klein_4b/klein_9b) forms so the legacy ~/.cache/huggingface/hub/models--flux_2_klein_4b_q8p.ckpt/... layout still resolves.

Fixes #23.

Test plan

  • darkbloom models1 (Download) → 1 (FLUX.2 Klein 4B): VAE completes, diffusion model begins streaming from R2 (flux-klein-4b-q8) at ~70+ MB/s on Apple M4 Pro.
  • Verified R2 URLs return 200 OK for flux_2_klein_4b_q8p.ckpt, flux_2_vae_f16.ckpt, qwen_3_4b_q8p.ckpt.
  • Confirm FLUX.2 Klein 9B downloads through the same path.
  • Smoke-check legacy HF-cache layout still resolves (klein_4b/klein_9b branch).

…ache path

`download_ckpt_model_from_cdn` matched the image-model pipeline against
`cache_dir.contains("flux_2_klein_{4,9}b_q8p")`, but `cmd_models` writes
image models to `~/.darkbloom/models/<s3_name>` (e.g. `flux-klein-4b-q8`),
so the match always fell through to the None arm and printed
"Unknown image model" after the tarball fallback 404'd.

Match against `base_url` (which carries the s3_name) in addition to
`cache_dir`, accepting both dashed (new) and underscored (legacy HF
cache) forms. Verified locally by downloading FLUX.2 Klein 4B end-to-end
from the R2 CDN via `darkbloom models`.

Fixes Layr-Labs#23
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 17, 2026

@lukevenediger is attempting to deploy a commit to the EigenLabs Team on Vercel.

A member of the Team first needs to authorize it.

@hankbobtheresearchoor
Copy link
Copy Markdown

Hermes Agent Review

Verdict: Minor suggestions

⚠️ Warning

  1. Substring matching is fragile and could match unintended model names — The check key.contains("klein-9b") would also match a hypothetical future model like flux-klein-9b-lora or klein-9b-quantized. Similarly, the combined key = format!("{} {}", base_url, cache_dir.to_string_lossy()) means a URL containing klein-9b in a path segment unrelated to the model (e.g., a bucket name or CDN prefix) could trigger a false match. Consider using more precise matching (e.g., exact segment match or regex with word boundaries).

  2. No test coverage for the matching logic — The pipeline selection is a critical dispatch path (wrong pipeline = wrong inference behavior), yet there are no unit tests verifying that various URL/cache-dir combinations resolve to the correct pipeline. A few test cases covering ~/.darkbloom/models/flux-klein-4b-q8, ~/.cache/huggingface/hub/models--flux_2_klein_4b_q8p.ckpt/..., and a non-matching path would go a long way.

💡 Suggestion

  1. Consider a lookup table instead of chained if — As more models are added, the if/else if chain will grow. A HashMap or slice of (pattern, ImagePipeline) would be more maintainable and easier to test in isolation.

  2. Log when pipeline is None — The original code already had an Unknown image model warning path, but it would be helpful to log the key value that failed to match, making it easier to diagnose future path resolution issues.

✅ Looks Good

  1. The core fix is correct — cache_dir alone was insufficient because cmd_models stores models under ~/.darkbloom/models/<s3_name>, not the HuggingFace cache layout. Including base_url in the match key resolves the root cause.

  2. Supporting both dashed and underscored forms ensures backward compatibility with existing HuggingFace cache directories.

Reviewed by Hermes Agent (hankbob)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v0.3.8: Not able to download FLUX.2 Klein 4B, getting "The requested URL returned error: 404"

2 participants