tracel-ai/burn · error
Failed to create cache file
Error message
Failed to create cache file
What it means
`download_if_needed` in the DISTS weights module panics with `File::create(cache_path).expect("Failed to create cache file")` when the cached VGG16 weights file (`vgg16-397923af.pth`) cannot be created after downloading. The cache directory was already ensured writable by `get_cache_dir`, so failures usually come from name collisions (path is a directory), races with another process, or sudden permission/quota changes. Triggered only when the file is not already cached.
Source
Thrown at crates/burn-train/src/metric/vision/dists/weights.rs:37
/// Get the cache directory for DISTS weights.
fn get_cache_dir() -> PathBuf {
let cache_dir = dirs::cache_dir()
.expect("Could not get cache directory")
.join("burn-dataset")
.join("dists");
if !cache_dir.exists() {
create_dir_all(&cache_dir).expect("Failed to create cache directory");
}
cache_dir
}
/// Download file if not cached.
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 weights into a DISTS module.
///
/// This loads both:
/// 1. ImageNet pretrained VGG16 backbone weights
/// 2. DISTS trained alpha/beta weights
///
/// Weights are cached in the user's cache directory to avoid re-downloading.
///
/// # Arguments
///
/// * `dists` - The DISTS module to load weights into.
///
/// # Returns
///View on GitHub (pinned to d16f7ba2ed)
Solutions
- Remove the stale entry: `rm -rf ~/.cache/burn-dists-cache-path/vgg16-397923af.pth` (or the whole dists cache dir) and retry
- Ensure the cache directory is writable by the running user (`chmod`/`chown`)
- Give each concurrent job its own XDG_CACHE_HOME, or pre-populate the cache once before parallel runs
- Check quota/free space on the cache volume
Example fix
// before (shell) mpirun -np 4 trainer # races on cache // after (shell) export XDG_CACHE_HOME=$HOME/.cache python -c "pre_populate()" # or run one warm-up job first rm -rf ~/.cache/burn-dataset/dists/vgg16-397923af.pth mpirun -np 4 trainer
Defensive patterns
Strategy: validation
Validate before calling
let dists_dir = dirs::cache_dir().unwrap().join("burn-dataset").join("dists");
let vgg = dists_dir.join("vgg16-397923af.pth");
if vgg.is_dir() { eprintln!("{} is a directory; remove it", vgg.display()); }
if !dists_dir.is_dir() || dists_dir.metadata().unwrap().permissions().readonly() {
eprintln!("dists cache dir not writable");
} Type guard
fn cache_file_creatable(dir: &std::path::Path, name: &str) -> bool {
let p = dir.join(name);
!p.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!("VGG16 cache file creation failed; clear the dists cache and retry"))?; Prevention
- Clear the dists cache entry after interrupted downloads
- Use per-job XDG_CACHE_HOME or a lock file when multiple workers populate the cache concurrently
- Verify the cache volume stays writable for the whole job (watch for remounts as read-only)
- Pre-download VGG16 weights once before fan-out runs
When it happens
Trigger: DISTS `load_pretrained_weights` with no cached VGG16 file: download succeeds, `File::create` fails because `vgg16-397923af.pth` exists as a directory, the dir became read-only, or quota was hit.
Common situations: Corrupted cache from an interrupted run; concurrent training jobs racing to populate the same cache; read-only mount appearing after startup; quota exhaustion on shared scratch volumes.
Related errors
- Failed to create cache file
- Failed to create cache directory
- Failed to write weights
- Failed to create cache directory
- Failed to write weights
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/8f3d3a754b3b855e.
Report an issue: GitHub.