{"record":{"id":"8f3d3a754b3b855e","repo":"tracel-ai/burn","slug":"failed-to-create-cache-file-8f3d3a","errorCode":null,"errorMessage":"Failed to create cache file","messagePattern":"Failed to create cache file","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/burn-train/src/metric/vision/dists/weights.rs","lineNumber":37,"sourceCode":"/// Get the cache directory for DISTS weights.\nfn get_cache_dir() -> PathBuf {\n    let cache_dir = dirs::cache_dir()\n        .expect(\"Could not get cache directory\")\n        .join(\"burn-dataset\")\n        .join(\"dists\");\n\n    if !cache_dir.exists() {\n        create_dir_all(&cache_dir).expect(\"Failed to create cache directory\");\n    }\n\n    cache_dir\n}\n\n/// Download file if not cached.\nfn download_if_needed(url: &str, cache_path: &PathBuf, message: &str) {\n    if !cache_path.exists() {\n        let bytes = download_file_as_bytes(url, message);\n        let mut file = File::create(cache_path).expect(\"Failed to create cache file\");\n        file.write_all(&bytes).expect(\"Failed to write weights\");\n    }\n}\n\n/// Download and load pretrained weights into a DISTS module.\n///\n/// This loads both:\n/// 1. ImageNet pretrained VGG16 backbone weights\n/// 2. DISTS trained alpha/beta weights\n///\n/// Weights are cached in the user's cache directory to avoid re-downloading.\n///\n/// # Arguments\n///\n/// * `dists` - The DISTS module to load weights into.\n///\n/// # Returns\n///","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/tracel-ai/burn/blob/d16f7ba2ed0d41408189384044cc886fb4c8f957/crates/burn-train/src/metric/vision/dists/weights.rs#L19-L55","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (shell)\nmpirun -np 4 trainer   # races on cache\n// after (shell)\nexport XDG_CACHE_HOME=$HOME/.cache\npython -c \"pre_populate()\"  # or run one warm-up job first\nrm -rf ~/.cache/burn-dataset/dists/vgg16-397923af.pth\nmpirun -np 4 trainer","handlingStrategy":"validation","validationCode":"let dists_dir = dirs::cache_dir().unwrap().join(\"burn-dataset\").join(\"dists\");\nlet vgg = dists_dir.join(\"vgg16-397923af.pth\");\nif vgg.is_dir() { eprintln!(\"{} is a directory; remove it\", vgg.display()); }\nif !dists_dir.is_dir() || dists_dir.metadata().unwrap().permissions().readonly() {\n    eprintln!(\"dists cache dir not writable\");\n}","typeGuard":"fn cache_file_creatable(dir: &std::path::Path, name: &str) -> bool {\n    let p = dir.join(name);\n    !p.is_dir() && std::fs::write(dir.join(\".probe\"), b\"\").is_ok()\n}","tryCatchPattern":"let weights = std::panic::catch_unwind(load_pretrained_weights)\n    .map_err(|_| anyhow!(\"VGG16 cache file creation failed; clear the dists cache and retry\"))?;","preventionTips":["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"],"tags":["panic","filesystem","permissions","download"],"backgroundTag":"cache-write-failed","analyzedSha":"d16f7ba2ed0d41408189384044cc886fb4c8f957","analyzedAt":"2026-09-05T13:19:14.260Z","contentChangedAt":"2026-09-05T13:19:14.260Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}