Skip to content
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

Update multiple-gpus-concise.md #1354

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

XihWang
Copy link

@XihWang XihWang commented Dec 14, 2024

因为d2l中的Resudual类已经更改为lazyconv2d,仅需要3个参数,而不是4个,此页的pytorch版本代码会出错。可以见d2l的源码:https://github.com/d2l-ai/d2l-en/blob/master/d2l/torch.py#L581 该链接中的Residual类的定义的一部分如下
class Residual(nn.Module):
"""The Residual block of ResNet models.

Defined in :numref:`sec_resnet`"""
def __init__(self, num_channels, use_1x1conv=False, strides=1):
    super().__init__()
    self.conv1 = nn.LazyConv2d(num_channels, kernel_size=3, padding=1,
                               stride=strides)
    self.conv2 = nn.LazyConv2d(num_channels, kernel_size=3, padding=1)
    if use_1x1conv:
        self.conv3 = nn.LazyConv2d(num_channels, kernel_size=1,
                                   stride=strides)
    else:
        self.conv3 = None
    self.bn1 = nn.LazyBatchNorm2d()
    self.bn2 = nn.LazyBatchNorm2d()

修改前:

image

修改后:

image

因为d2l中的Resudual类已经更改为lazyconv2d,仅需要3个参数,而不是4个,此页的pytorch版本代码会出错。可以见d2l的源码:https://github.com/d2l-ai/d2l-en/blob/master/d2l/torch.py#L581
该链接中的Residual类的定义的一部分如下
class Residual(nn.Module):
    """The Residual block of ResNet models.

    Defined in :numref:`sec_resnet`"""
    def __init__(self, num_channels, use_1x1conv=False, strides=1):
        super().__init__()
        self.conv1 = nn.LazyConv2d(num_channels, kernel_size=3, padding=1,
                                   stride=strides)
        self.conv2 = nn.LazyConv2d(num_channels, kernel_size=3, padding=1)
        if use_1x1conv:
            self.conv3 = nn.LazyConv2d(num_channels, kernel_size=1,
                                       stride=strides)
        else:
            self.conv3 = None
        self.bn1 = nn.LazyBatchNorm2d()
        self.bn2 = nn.LazyBatchNorm2d()
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