ropas / pytea Goto Github PK
View Code? Open in Web Editor NEWPyTea: PyTorch Tensor shape error analyzer
Home Page: https://sf.snu.ac.kr/pytea/
License: Other
PyTea: PyTorch Tensor shape error analyzer
Home Page: https://sf.snu.ac.kr/pytea/
License: Other
Hi, I have met a problem while detecting LSTM tensor shape errors.
The testing file below is runnable and pytea returns correctly.
import torch
import torch.nn as nn
import torch.nn.functional as F
class Model(nn.Module):
def __init__(self):
super().__init__()
self.cnn = nn.Conv2d(3, 1, 3, 1, 1)
self.rnn = nn.LSTM(32, 64, 1, batch_first=True)
self.pool = nn.MaxPool2d(2, 2)
self.fc = nn.Linear(64, 16)
def forward(self, x):
x = self.pool(F.relu(self.cnn(x)))
x = x.view(-1, 32, 32)
x, _ = self.rnn(x)
x = x[:, -1, :].squeeze(1)
x = F.relu(self.fc(x))
x = F.softmax(x, dim=-1)
return x
if __name__ == "__main__":
net = Model()
x = torch.randn(2, 3, 64, 64)
y = net(x)
target = torch.argmax(torch.randn(2, 16), dim=-1)
loss = F.cross_entropy(y, target.long())
loss.backward()
print(y.size())
However, If I change self.rnn = nn.LSTM(32, 64, 1, batch_first=True)
into self.rnn = nn.LSTM(64, 64, 1, batch_first=True)
, torch will report a RuntimeError: Expected 64, got 32.
pytea didn't return any CONSTRAINTS information, as it supposed to.
Then I tried to more LSTM input_size shape errors, all failed. Same situation with GRU.
I think it is a bug, because I can detect Conv2d, Linear error successfully.
아래와 같은 코드 실행에서 문제가 발생한다는 것을 깨달았습니다.
x = 0 if 0 <= 1 else 1
# runtime output
REDUCED HEAP: (size: 250)
x => 1
파이썬의 삼항연산자가 x = (((0 <= 1) and 0) or 1)
로 파싱됩니다.
Logical statement가 True, true-value가 0일 때 발생하는 오류인 것으로 보입니다.
당장 벤치마크 코드에서 나타나는 문제는 아닙니다.
Pylib builtin 구현에서 발생한 문제이므로, 다른 방식으로 구현함으로써 일단은 피해갈 수 있을 것 같습니다.
감사합니다.
Hello, I have encountered the following problems:
First question:
The content of my source file is:
import torch
import torch.nn as nn
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.layers = nn.Sequential(
nn.Linear(28 * 28, 120),
nn.ReLU(),
nn.Linear(80, 10))
def a(self):
pass
if __name__ == "__main__":
n = Net()
But when I execute the command, I get the following results:
There should be a problem with defining shape in this model.
Second question:
I used it https://github.com/pytorch/examples/blob/master/mnist/main.py , but the command is stuck and no result is returned. As follows:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.