pytorch/pytorch · error · ValueError
Pattern must contain a single '->' separator
Error message
Pattern must contain a single '->' separator
What it means
Thrown by `_split_pattern`/`parse_pattern` in functorch/einops `_parsing.py`. `pattern.split('->')` must yield exactly two parts; zero separators or more than one `->` raises this ValueError (the original exception is suppressed with `from None`).
Source
Thrown at functorch/einops/_parsing.py:227
def parse_pattern(
pattern: str, axes_lengths: Mapping[str, int]
) -> tuple[ParsedExpression, ParsedExpression]:
"""Parse an `einops`-style pattern into a left-hand side and right-hand side `ParsedExpression` object.
Args:
pattern (str): the `einops`-style rearrangement pattern
axes_lengths (Mapping[str, int]): any additional length specifications for dimensions
Returns:
tuple[ParsedExpression, ParsedExpression]: a tuple containing the left-hand side and right-hand side expressions
"""
# adapted from einops.einops._prepare_transformation_recipe
# https://github.com/arogozhnikov/einops/blob/230ac1526c1f42c9e1f7373912c7f8047496df11/einops/einops.py
try:
left_str, right_str = pattern.split("->")
except ValueError:
raise ValueError("Pattern must contain a single '->' separator") from None
if _ellipsis in axes_lengths:
raise ValueError(f"'{_ellipsis}' is not an allowed axis identifier")
left = ParsedExpression(left_str)
right = ParsedExpression(right_str)
if not left.has_ellipsis and right.has_ellipsis:
raise ValueError(
f"Ellipsis found in right side, but not left side of a pattern {pattern}"
)
if left.has_ellipsis and left.has_ellipsis_parenthesized:
raise ValueError(
f"Ellipsis is parenthesis in the left side is not allowed: {pattern}"
)
return left, right
View on GitHub (pinned to dcd2ecae77)
Solutions
- Ensure the pattern has exactly one `->` separating left and right sides
- Chain multiple rearrange calls instead of trying to encode multiple steps in one pattern
- Validate `pattern.count('->') == 1` before calling the API
Example fix
# before y = rearrange(x, 'b (h w)') # missing '->' # after y = rearrange(x, 'b (h w) -> b h w')
Defensive patterns
Strategy: validation
Validate before calling
def has_single_arrow(pattern: str) -> bool:
return pattern.count("->") == 1 Try / catch
try:
y = rearrange(x, pattern)
except ValueError as e:
if "single '->' separator" in str(e):
raise ValueError(f"pattern {pattern!r} needs exactly one '->'") from e
raise Prevention
- Always write both sides: 'input_axes -> output_axes'
- Chain rearrange calls instead of multi-arrow patterns
When it happens
Trigger: Patterns with no `->` (`'b c'`) or with multiple `->` (`'a -> b -> c'`, or a side containing '->' after template concatenation).
Common situations: Missing arrow when writing a quick pattern; chaining attempted in one string; pattern strings built by joining fragments that each contain an arrow.
Related errors
- Anonymous axis should have positive length, not {self.value}
- Expression may contain dots only inside ellipsis (...)
- Expression may contain dots only inside ellipsis (...); only
- Indexing expression contains duplicate dimension '{x}'
- Invalid axis identifier: {x}\n{reason}
AI-assisted analysis of pytorch/pytorch@dcd2ecae77 (2026-08-14).
Data as JSON: /api/errors/467ed08909d4b767.
Report an issue: GitHub.