tracel-ai/burn · error
Invalid regex pattern
Error message
Invalid regex pattern
What it means
Regex validation guard in `PytorchStore::with_key_remapping`: the `from_pattern` is compiled as a regex for tensor-name remapping during load; an invalid pattern panics instead of producing a silently non-matching remapper.
Source
Thrown at crates/burn-store/src/pytorch/store.rs:249
/// Add a regex pattern to remap tensor names during load.
///
/// # Example
/// ```rust,no_run
/// # use burn_store::PytorchStore;
/// let store = PytorchStore::from_file("model.pth")
/// .with_key_remapping(r"^encoder\.", "transformer.encoder.") // encoder.X -> transformer.encoder.X
/// .with_key_remapping(r"\.gamma$", ".weight"); // X.gamma -> X.weight
/// ```
pub fn with_key_remapping(
mut self,
from_pattern: impl AsRef<str>,
to_pattern: impl Into<String>,
) -> Self {
self.remapper = self
.remapper
.add_pattern(from_pattern, to_pattern)
.expect("Invalid regex pattern");
self
}
/// Set whether to validate tensors during loading (default: true).
pub fn validate(mut self, validate: bool) -> Self {
self.validate = validate;
self
}
/// Allow partial loading of tensors (continue even if some tensors are missing).
pub fn allow_partial(mut self, allow: bool) -> Self {
self.allow_partial = allow;
self
}
/// Skip enum variant names when matching tensor paths (default: true).
///
/// When enabled, tensor paths from PyTorch that don't include enum variantsView on GitHub (pinned to d16f7ba2ed)
Solutions
- Pre-validate the pattern with `Regex::new`
- Fix regex escapes (e.g., `\.` for literal dots) in the pattern
- Test the pattern against expected key names before building the store
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/burn-store/src/pytorch/store.rs:249 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05).
Data as JSON: /api/errors/7e68d65d6cb2b5bd.
Report an issue: GitHub.