Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions mmengine/runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import warnings
from collections import OrderedDict
from functools import partial
from inspect import isclass
from typing import Callable, Dict, List, Optional, Sequence, Union

import torch
Expand Down Expand Up @@ -902,8 +903,13 @@ def wrap_model(
find_unused_parameters=find_unused_parameters)
else:
model_wrapper_cfg.setdefault('type', 'MMDistributedDataParallel')
model_wrapper_type = MODEL_WRAPPERS.get(
model_wrapper_cfg.get('type')) # type: ignore
model_wrapper_type = model_wrapper_cfg.get('type')
if isinstance(model_wrapper_type, str):
model_wrapper_type = MODEL_WRAPPERS.get(model_wrapper_type)
else:
assert isclass(
model_wrapper_type), 'type should be a string or a class'
Comment on lines +910 to +911
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertion should raise a TypeError instead of using an assert statement for better error handling. Assert statements can be disabled with Python optimization flags (-O), making this validation unreliable in production. Consider:

if not isclass(model_wrapper_type):
    raise TypeError('type should be a string or a class')
Suggested change
assert isclass(
model_wrapper_type), 'type should be a string or a class'
if not isclass(model_wrapper_type):
raise TypeError('type should be a string or a class')

Copilot uses AI. Check for mistakes.
Comment on lines +906 to +911
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new functionality that allows passing a class directly as the type value (instead of a string) lacks test coverage. Consider adding a test case that validates this behavior:

# Example test case
cfg.model_wrapper_cfg = dict(type=CustomModelWrapper)  # Pass class directly
runner = Runner.from_cfg(cfg)
self.assertIsInstance(runner.model, CustomModelWrapper)

Copilot uses AI. Check for mistakes.

default_args: dict = dict()
if issubclass(
model_wrapper_type, # type: ignore
Expand Down