Skip to content

fix(model): effective-rank and dormant-ratio logging call sites raise TypeError - #504

Open
Anai-Guo wants to merge 1 commit into
opendilab:mainfrom
Anai-Guo:fix-effective-rank-and-dormant-ratio-call-sites
Open

Anai-Guo wants to merge 1 commit into
opendilab:mainfrom
Anai-Guo:fix-effective-rank-and-dormant-ratio-call-sites

Conversation

@Anai-Guo

@Anai-Guo Anai-Guo commented Sep 4, 2026

Copy link
Copy Markdown

Two call sites in the "logging for analysis" path raise TypeError the moment the metric is enabled. Both are single-token mismatches against helpers that the sibling file already calls correctly.

1. world_model.py calls the wrong *_effective_rank

lzero/model/utils.py has two similarly named helpers:

def compute_effective_rank(singular_values: np.ndarray) -> float:            # :38
def calculate_effective_rank(model, inputs, representation_layer_name) -> float:   # :83

world_model.py imports the first one and calls it with the second one's arguments:

# lzero/model/unizero_world_models/world_model.py:2525
e_rank_last_linear = compute_effective_rank(
    self.tokenizer.encoder, inputs, representation_layer_name="last_linear"
)

world_model_multitask.py:1878 — the sibling implementation of the same block — already does it right:

e_rank_last_linear = calculate_effective_rank(
    self.tokenizer.encoder[encoder_index], inputs, representation_layer_name="last_linear")

So this changes the import and the two call sites to calculate_effective_rank. compute_effective_rank is not used anywhere else in world_model.py, and is still used internally by calculate_effective_rank (utils.py:133).

2. muzero.py passes percentage= to calculate_dormant_ratio

def calculate_dormant_ratio(model, inputs, dormant_threshold=1e-2, target_modules=...)   # utils.py:160

muzero.py:434 and :505 pass percentage=self._cfg.dormant_threshold. The config key is already called dormant_threshold; only the keyword is stale. world_model.py:2507 and world_model_multitask.py:1869 both use dormant_threshold=.

This is gated on if self._cfg.calculate_dormant_ratio: (default False), which is why it has stayed unnoticed — but turning that analysis flag on crashes the learn step immediately.

Verification

lzero/model/utils.py was loaded verbatim via importlib (not through the lzero package, so no ditk needed) and both call sites were replayed against a small nn.Module on CPU:

compute_effective_rank   (singular_values: numpy.ndarray) -> float
calculate_effective_rank (model, inputs, representation_layer_name: str) -> float
calculate_dormant_ratio  (model, inputs, dormant_threshold: float = 0.01, target_modules=...) -> Dict[str, float]

=== world_model.py:2525 — effective rank of a named layer ===
  compute_effective_rank  (on main): TypeError: compute_effective_rank() got an unexpected keyword argument 'representation_layer_name'
  calculate_effective_rank (patched): -> 7.2696

=== muzero.py:433 — dormant ratio ===
  percentage=          (on main): TypeError: calculate_dormant_ratio() got an unexpected keyword argument 'percentage'
  dormant_threshold=  (patched): -> global=52.3438

Both patched calls return a real number rather than merely binding, so the helpers do run end to end (forward hook fires, SVD computed).

No functional change anywhere else; compute_average_weight_magnitude and the surrounding logging are untouched.

🤖 Generated with Claude Code

…ly have

Two call sites in the dormant-ratio / effective-rank logging path cannot bind:

* world_model.py imports compute_effective_rank(singular_values) but calls it
  as calculate_effective_rank(model, inputs, representation_layer_name=...),
  which raises TypeError. world_model_multitask.py already imports and calls
  calculate_effective_rank with exactly these arguments.
* muzero.py passes percentage= to calculate_dormant_ratio, whose threshold
  argument is named dormant_threshold. Both world_model.py and
  world_model_multitask.py already use dormant_threshold=.

Signed-off-by: Tai An <antai12232931@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant