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

jittor.nn.ConstantPad2d报错local variable 'i' referenced before assignment #590

Open
PhyllisJi opened this issue Sep 6, 2024 · 0 comments

Comments

@PhyllisJi
Copy link

Describe the bug

可能是上一层的shape为[1,128,]导致,但是该API没有对输入形状进行检查并合理地抛出异常,另外jittor不支持ConstantPad1d

Full Log

---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
Cell In[6], line 55
     51     y = m(x)
     52     return list(y.shape)
---> 55 go()

Cell In[6], line 51, in go()
     49 x = jittor.randn([1, 3, 224, 224])
     50 m = alexnet()
---> 51 y = m(x)
     52 return list(y.shape)

File ~/miniconda3/envs/myconda/lib/python3.9/site-packages/jittor/__init__.py:1168, in Module.__call__(self, *args, **kw)
   1167 def __call__(self, *args, **kw):
-> 1168     return self.execute(*args, **kw)

Cell In[6], line 41, in alexnet.execute(self, x)
     39 x = self.relu5_mutated(x)
     40 print(x.shape)
---> 41 x = self.pool3_mutated(x)
     42 return x

File ~/miniconda3/envs/myconda/lib/python3.9/site-packages/jittor/__init__.py:1168, in Module.__call__(self, *args, **kw)
   1167 def __call__(self, *args, **kw):
-> 1168     return self.execute(*args, **kw)

File ~/miniconda3/envs/myconda/lib/python3.9/site-packages/jittor/nn.py:1694, in ConstantPad2d.execute(self, x)
   1692 for i in range(len(shape)-2):
   1693     tar_dims.append(f"i{i}")
-> 1694 tar_dims.append(f"i{i+1}-{self.pt}")
   1695 tar_dims.append(f"i{i+2}-{self.pl}")
   1696 return x.reindex(tar_shape, tar_dims, overflow_value=self.value)

UnboundLocalError: local variable 'i' referenced before assignment

Minimal Reproduce

import os
os.environ["disable_lock"] = "1"
import jittor
import jittor.nn as nn
import jittor.optim as optim
import numpy as np
import copy


class alexnet(nn.Module):
    def __init__(self):
        super().__init__()
        self.conv1_mutated = jittor.nn.Conv2d(in_channels=3, out_channels=64, kernel_size=6, stride=4, padding=2)
        self.relu1_mutated = jittor.nn.ReLU()
        self.pool1_mutated = jittor.nn.ZeroPad2d(padding=(1, 5, 7, 1))
        self.conv2_mutated = jittor.nn.UpsamplingNearest2d(scale_factor=1.0)
        self.relu2_mutated = jittor.nn.GELU()
        self.pool2_mutated = jittor.nn.MaxPool2d(kernel_size=(3, 6), stride=8, ceil_mode=False, return_indices=False, padding=(6, 3))
        self.conv3_mutated = jittor.nn.Sigmoid()
        self.relu3_mutated = jittor.nn.ELU()
        self.conv4_mutated = jittor.nn.MaxPool2d(kernel_size=(3, 7), return_indices=False, stride=(6, 2))
        self.relu4_mutated = jittor.nn.ReLU()
        self.conv5_mutated = jittor.nn.Flatten()
        self.relu5_mutated = jittor.nn.Softmax()
        self.pool3_mutated = jittor.nn.ConstantPad2d(padding=5, value=0.0)
    
    def execute(self, x):
        x = self.conv1_mutated(x)
        x = self.relu1_mutated(x)
        x = self.pool1_mutated(x)
        x = self.conv2_mutated(x)
        x = self.relu2_mutated(x)
        x = self.pool2_mutated(x)
        x = self.conv3_mutated(x)
        x = self.relu3_mutated(x)
        x = self.conv4_mutated(x)
        x = self.relu4_mutated(x)
        x = self.conv5_mutated(x)
        x = self.relu5_mutated(x)
        print(x.shape)
        x = self.pool3_mutated(x)
        return x

def go():
    jittor.flags.use_cuda = 1
    x = jittor.randn([1, 3, 224, 224])
    m = alexnet()
    y = m(x)
    return list(y.shape)

go()
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

No branches or pull requests

1 participant