.xshape.rename_expressions¶
- class experimental_experiment.xshape.rename_expressions.RenameTransformer(mapping, expr: str | None = None)[source]¶
- class experimental_experiment.xshape.rename_expressions.RenameVariable(mapping, expr: str | None = None)[source]¶
- experimental_experiment.xshape.rename_expressions.parse_expression_tokens(expr: str) Set[str] [source]¶
Extracts the token from an expression.
- experimental_experiment.xshape.rename_expressions.rename_dynamic_dimensions(constraints: Dict[str, Set[str]], original: Set[str], ban_prefix: str = 'DYN') Dict[str, str] [source]¶
Renames dynamic shapes as requested by the user.
torch.export.export()
uses many names for dynamic dimensions. When building the onnx model, some of them are redundant and can be replaced by the name provided by the user.- Parameters:
constraints – exhaustive list of used name and all the values equal to it
original – the names to use if possible
ban_prefix – avoid any rewriting by a constant starting with this prefix
- Returns:
replacement dictionary
- experimental_experiment.xshape.rename_expressions.rename_dynamic_expression(expression: str, replacements: Dict[str, str])[source]¶
Renames variables inside an expression. The function removes any space.
- Parameters:
expression – something like
s15 + seq_length
replacements – replacements to make
- Returns:
new string