huggingface/transformers · error · ValueError
WeightConverter requires at least one operation.
Error message
WeightConverter requires at least one operation.
What it means
Raised by WeightConverter.__init__ (core_model_loading.py:1154). A WeightConverter is defined by its list of tensor operations (the actual conversion math); an empty operations list means there is nothing to convert, which almost always indicates the caller passed an uninitialized/empty list or forgot the argument. The constructor validates this after the cardinality check and refuses to build an operation-less converter.
Source
Thrown at src/transformers/core_model_loading.py:1154
class WeightConverter(WeightTransform):
__slots__ = ("operations",)
def __init__(
self, source_patterns: str | list[str], target_patterns: str | list[str], operations: list[ConversionOps]
):
super().__init__(source_patterns, target_patterns)
self.operations: list[ConversionOps] = operations
if bool(len(self.source_patterns) - 1) + bool(len(self.target_patterns) - 1) >= 2:
# We allow many-to-many only if we use an internal operation that can handle it
if not any(isinstance(op, _INTERNAL_MANY_TO_MANY_CONVERSIONS) for op in self.operations):
raise ValueError(
f"source keys={self.source_patterns}, target_patterns={self.target_patterns} but you can only have one to many, one to one or many to one."
)
if not self.operations:
raise ValueError("WeightConverter requires at least one operation.")
def convert(
self,
layer_name: str,
model=None,
config=None,
hf_quantizer=None,
loading_info: LoadStateDictInfo | None = None,
):
# Collect the tensors here - we use a new dictionary to avoid keeping them in memory in the internal
# attribute during the whole process
collected_tensors = self.materialize_tensors()
for op in self.operations:
with log_conversion_errors(layer_name, loading_info, (len(collected_tensors), layer_name), op):
collected_tensors = op.convert(
collected_tensors,
source_patterns=self.source_patterns,View on GitHub (pinned to a597f97485)
Solutions
- If you only need key renaming with no tensor math, use WeightTransform/GroupWeightRename/PrefixChange instead of WeightConverter.
- If tensor conversion is intended, pass at least one op (e.g. Identity-like op or the real conversion) in operations.
- In programmatic builders, assert the ops list is non-empty before constructing to surface the upstream logic error.
Example fix
# before WeightConverter(source_patterns=[r'blk.*'], target_patterns=[r'layers.*'], operations=ops) # ops == [] # after: pure rename -> WeightTransform WeightTransform(source_patterns=[r'blk.*'], target_patterns=[r'layers.*'])
Defensive patterns
Strategy: validation
Validate before calling
assert isinstance(operations, list) and len(operations) > 0, (
'WeightConverter needs >=1 operation; use WeightTransform for pure renames'
) Type guard
def has_operations(operations) -> bool:
return bool(operations) Prevention
- Use WeightTransform (or GroupWeightRename/PrefixChange) for pure key renames — no operations needed.
- Assert ops lists are non-empty where they are built dynamically (loops/filters).
- Lint recipes for WeightConverter instantiations with literal empty operations=[].
When it happens
Trigger: WeightConverter(source_patterns=[...], target_patterns=[...], operations=[]) — e.g. operations were built conditionally and the condition never fired, leaving an empty list; or a refactor left the default empty list in place.
Common situations: Programmatic recipe builders that accumulate ops in a loop which never executes (empty config section, wrong filter), or copy-paste where the operations argument was dropped. If you only need a rename, use WeightTransform (no operations) instead of WeightConverter.
Related errors
- GroupWeightRename requires N:N length matching, but found le
- You must provide only one of `prefix_to_add` and `prefix_to_
- source keys={self.source_patterns}, target_patterns={self.ta
- Multiple different capturing groups found in target_patterns
- Source pattern '{pattern}' contains \\1 backreference, but n
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/fd52d12afb660a6d.
Report an issue: GitHub.