-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix issue when using latest omegaconf
Summary: `ShapeSpec` was a namedtuple, which supports both indexing and attribute access. This confused the latest omegaconf: lastest omegaconf interprets it as a tuple instead. We never need to index ShapeSpec like `input_shape[0]`. Only attribute access like `input_shape.channels` is needed. So this PR changes it to dataclass. And it also hardens the dataclass support in LazyConfig so that `instantiate()`, etc works correctly with it. Follow up of 32c32e3. sstsai-adl I think this will fix the error you're seeing. Pull Request resolved: #4253 Reviewed By: sstsai-adl Differential Revision: D36635140 fbshipit-source-id: 8526ebc546941c448cdf9afe77a946ef612c74a5
- Loading branch information
1 parent
45b3fce
commit 3cc9908
Showing
6 changed files
with
85 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,20 +1,18 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
from collections import namedtuple | ||
from dataclasses import dataclass | ||
from typing import Optional | ||
|
||
|
||
class ShapeSpec(namedtuple("_ShapeSpec", ["channels", "height", "width", "stride"])): | ||
@dataclass | ||
class ShapeSpec: | ||
""" | ||
A simple structure that contains basic shape specification about a tensor. | ||
It is often used as the auxiliary inputs/outputs of models, | ||
to complement the lack of shape inference ability among pytorch modules. | ||
Attributes: | ||
channels: | ||
height: | ||
width: | ||
stride: | ||
""" | ||
|
||
def __new__(cls, channels=None, height=None, width=None, stride=None): | ||
return super().__new__(cls, channels, height, width, stride) | ||
channels: Optional[int] = None | ||
height: Optional[int] = None | ||
width: Optional[int] = None | ||
stride: Optional[int] = None |
This file contains 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 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 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