tracel-ai/burn · error
Failed to create cache directory
Error message
Failed to create cache directory
What it means
In the FID weights module, `get_cache_dir()` panics via `create_dir_all(&cache_dir).expect("Failed to create cache directory")` when `~/.cache/burn-dataset/fid` cannot be created. The cache root resolved fine, but mkdir failed — permissions, read-only filesystem, quota, or a non-directory file at the target path. This blocks FID `load_pretrained_weights` before the Inception download begins.
Source
Thrown at crates/burn-train/src/metric/vision/fid/weights.rs:18
use burn_std::network::downloader::download_file_as_bytes;
use burn_store::{ModuleSnapshot, PytorchStore};
use std::fs::{File, create_dir_all};
use std::io::Write;
use std::path::PathBuf;
use super::metric::Fid;
const INCEPTION_WEIGHTS_URL: &str = "https://github.com/mseitzer/pytorch-fid/releases/download/fid_weights/pt-inception-2015-12-05-6726825d.pth";
fn get_cache_dir() -> PathBuf {
let cache_dir = dirs::cache_dir()
.expect("Could not get cache directory")
.join("burn-dataset")
.join("fid");
if !cache_dir.exists() {
create_dir_all(&cache_dir).expect("Failed to create cache directory");
}
cache_dir
}
fn download_if_needed(url: &str, cache_path: &PathBuf, message: &str) {
if !cache_path.exists() {
let bytes = download_file_as_bytes(url, message);
let mut file = File::create(cache_path).expect("Failed to create cache file");
file.write_all(&bytes).expect("Failed to write weights");
}
}
/// Download and load pretrained pytorch-fid InceptionV3 weights.
///
/// Weights are cached in `~/.cache/burn-dataset/fid/`.
pub fn load_pretrained_weights(mut fid: Fid) -> Fid {
let cache_dir = get_cache_dir();View on GitHub (pinned to d16f7ba2ed)
Solutions
- Repair permissions: `mkdir -p ~/.cache/burn-dataset && chown -R $(whoami) ~/.cache/burn-dataset`
- Remove a colliding non-directory file at `~/.cache/burn-dataset/fid`
- Redirect via `XDG_CACHE_HOME` to a writable, pre-created directory
- In containerized deployments, mount an emptyDir/volume at the cache path and run as a consistent user
Example fix
// before (Dockerfile) USER 1000 CMD ["./trainer"] // after (Dockerfile) ENV XDG_CACHE_HOME=/home/app/.cache RUN mkdir -p /home/app/.cache/burn-dataset/fid && chown -R 1000 /home/app/.cache USER 1000 CMD ["./trainer"]
Defensive patterns
Strategy: validation
Validate before calling
let fid_dir = dirs::cache_dir().unwrap().join("burn-dataset").join("fid");
std::fs::create_dir_all(&fid_dir).expect("cannot prepare fid cache dir");
if fid_dir.exists() && !fid_dir.is_dir() {
eprintln!("{} blocks the cache dir; remove it", fid_dir.display());
} Type guard
fn cache_dir_writable(dir: &std::path::Path) -> bool {
dir.is_dir() && std::fs::write(dir.join(".probe"), b"").is_ok()
} Try / catch
let weights = std::panic::catch_unwind(load_pretrained_weights)
.map_err(|_| anyhow!("fid cache dir creation failed; check ~/.cache permissions"))?; Prevention
- Pre-create ~/.cache/burn-dataset/fid during setup with correct ownership
- Avoid mixing root and non-root runs against the same home cache
- Mount writable volumes when the rootfs is read-only
- Remove non-directory files that collide with the cache path before running
When it happens
Trigger: First FID `load_pretrained_weights` call when the fid cache dir is missing and `create_dir_all` fails: `~/.cache` not writable, root-owned `burn-dataset` from an earlier root run, read-only rootfs, or a stale file named `fid` in `burn-dataset`.
Common situations: User mismatch between cache creator and runner; immutable container images without a writable cache volume mount; quotas on home directories; leftovers colliding with the cache path.
Related errors
- Failed to create cache directory
- Failed to create cache directory
- Could not get cache directory
- Failed to create cache file
- Could not get cache directory
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/1f59e911c30e76ba.
Report an issue: GitHub.