-
Notifications
You must be signed in to change notification settings - Fork 21
fix(PTv3): checkpoint load for testing #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
amadeuszsz
merged 6 commits into
tier4:main
from
amadeuszsz:fix/ptv3-test-checkpoint-load
Mar 13, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d47f4bb
fix(PTv3): checkpoint load for testing
amadeuszsz 784c7e2
fix(PTv3): set spconv2
amadeuszsz 93f19bc
ci(pre-commit): autofix
pre-commit-ci[bot] 6b363a6
fix(PTv3): simplification & adjust comment
amadeuszsz 3578a47
fix(PTv3): remove mmdetection3d's spconv patch by patch
amadeuszsz acb32d2
ci(pre-commit): autofix
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| --- /mmdet3d/models/layers/spconv/overwrite_spconv/write_spconv2.py | ||
| +++ /mmdet3d/models/layers/spconv/overwrite_spconv/write_spconv2.py.corrected | ||
| @@ -1,9 +1,6 @@ | ||
| # Copyright (c) OpenMMLab. All rights reserved. | ||
| -import itertools | ||
| -from typing import List, OrderedDict | ||
|
|
||
| from mmengine.registry import MODELS | ||
| -from torch.nn.parameter import Parameter | ||
|
|
||
|
|
||
| def register_spconv2() -> bool: | ||
| @@ -44,69 +41,4 @@ def register_spconv2() -> bool: | ||
| MODELS._register_module(SubMConv3d, 'SubMConv3d', force=True) | ||
| MODELS._register_module(SubMConv4d, 'SubMConv4d', force=True) | ||
| SparseModule._version = 2 | ||
| - SparseModule._load_from_state_dict = _load_from_state_dict | ||
| return True | ||
| - | ||
| - | ||
| -def _load_from_state_dict(self, state_dict: OrderedDict, prefix: str, | ||
| - local_metadata: dict, strict: bool, | ||
| - missing_keys: List[str], unexpected_keys: List[str], | ||
| - error_msgs: List[str]) -> None: | ||
| - """Rewrite this func to compat the convolutional kernel weights between | ||
| - spconv 1.x in MMCV and 2.x in spconv2.x. | ||
| - | ||
| - Kernel weights in MMCV spconv has shape in (D,H,W,in_channel,out_channel) , | ||
| - while those in spcon2.x is in (out_channel,D,H,W,in_channel). | ||
| - """ | ||
| - version = local_metadata.get('version', None) | ||
| - for hook in self._load_state_dict_pre_hooks.values(): | ||
| - hook(state_dict, prefix, local_metadata, strict, missing_keys, | ||
| - unexpected_keys, error_msgs) | ||
| - | ||
| - local_name_params = itertools.chain(self._parameters.items(), | ||
| - self._buffers.items()) | ||
| - local_state = {k: v.data for k, v in local_name_params if v is not None} | ||
| - | ||
| - for name, param in local_state.items(): | ||
| - key = prefix + name | ||
| - if key in state_dict: | ||
| - input_param = state_dict[key] | ||
| - | ||
| - # Backward compatibility: loading 1-dim tensor from | ||
| - # 0.3.* to version 0.4+ | ||
| - if len(param.shape) == 0 and len(input_param.shape) == 1: | ||
| - input_param = input_param[0] | ||
| - if version != 2: | ||
| - dims = [len(input_param.shape) - 1] + list( | ||
| - range(len(input_param.shape) - 1)) | ||
| - input_param = input_param.permute(*dims) | ||
| - if input_param.shape != param.shape: | ||
| - # local shape should match the one in checkpoint | ||
| - error_msgs.append( | ||
| - f'size mismatch for {key}: copying a param with ' | ||
| - f'shape {key, input_param.shape} from checkpoint,' | ||
| - f'the shape in current model is {param.shape}.') | ||
| - continue | ||
| - | ||
| - if isinstance(input_param, Parameter): | ||
| - # backwards compatibility for serialized parameters | ||
| - input_param = input_param.data | ||
| - try: | ||
| - param.copy_(input_param) | ||
| - except Exception: | ||
| - error_msgs.append( | ||
| - f'While copying the parameter named "{key}", whose ' | ||
| - f'dimensions in the model are {param.size()} and whose ' | ||
| - f'dimensions in the checkpoint are {input_param.size()}.') | ||
| - elif strict: | ||
| - missing_keys.append(key) | ||
| - | ||
| - if strict: | ||
| - for key, input_param in state_dict.items(): | ||
| - if key.startswith(prefix): | ||
| - input_name = key[len(prefix):] | ||
| - input_name = input_name.split( | ||
| - '.', 1)[0] # get the name of param/buffer/child | ||
| - if input_name not in self._modules \ | ||
| - and input_name not in local_state: | ||
| - unexpected_keys.append(key) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.