Open twist-vector opened 1 month ago
@twist-vector thanks for filing this issue. Is this built from the same commit you shared on discord? 0d1eb7d95983ad7f42faadf86dc66e186f53f264
?
Yes.
On Wed, Oct 23, 2024, 7:47 PM Dalar Vartanians @.***> wrote:
@twist-vector https://github.com/twist-vector thanks for filing this issue. Is this built from the same commit you shared on discord? 0d1eb7d95983ad7f42faadf86dc66e186f53f264 ?
— Reply to this email directly, view it on GitHub https://github.com/tenstorrent/tt-metal/issues/14140#issuecomment-2433793580, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE3H3CAKCOLP5EVW73VMOTZ5AYRZAVCNFSM6AAAAABQOPFJL2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMZTG44TGNJYGA . You are receiving this because you were mentioned.Message ID: @.***>
import torch import ttnn import torch.nn.functional as F
device_params = {"l1_small_size": 24576} device = ttnn.CreateDevice(device_id=0, **device_params)
BATCH_SIZE = 1 CHANNELS = 1 MAT_SIZE = 32 KERN_SIZE = 3
input_tensor = torch.ones((BATCH_SIZE, CHANNELS, MAT_SIZE, MAT_SIZE), dtype=torch.float32)
weight_tensor = torch.ones((CHANNELS, CHANNELS, KERN_SIZE, KERN_SIZE), dtype=torch.float32)
output = F.conv2d(input_tensor, weight_tensor, stride=1, padding=1)
input_tensor_ttnn = ttnn.from_torch(input_tensor, layout=ttnn.TILE_LAYOUT, device=device) weight_tensor_ttnn = ttnn.from_torch(weight_tensor, layout=ttnn.TILE_LAYOUT, device=device)
print("Torch output size:", output.shape)
res = ttnn.conv2d( input_tensor=input_tensor_ttnn, weight_tensor=weight_tensor_ttnn, device=device, in_channels=CHANNELS, out_channels=CHANNELS, batch_size=BATCH_SIZE, input_height=MAT_SIZE, input_width=MAT_SIZE, kernel_size=(KERN_SIZE, KERN_SIZE), padding=(1, 1), stride=(1, 1), dilation=(1, 1), groups=1, ) out, out_height, out_width, conv_weight_tensor, conv_bias_tensor = res
out_torch = ttnn.to_torch(out).squeeze(-1).reshape(1, 1, MAT_SIZE, MAT_SIZE)
out_torch = out_torch.to(torch.float32) print("Do we get the same output from torch and TTNN?", torch.allclose(out_torch, output, atol=1e-6))
print("TTNN output:", out_torch) print("Torch output:", output)
ttnn.close_device(device)
@mywoodstock I have commented and slightly modified the test example above ^. Not sure my the TTNN and torch outputs are different here. Could you pls take a look?
@mywoodstock perhaps the issue is that we need this kind of pre-processing?
def preprocess_linear_weight(weight, *, dtype, layout=ttnn.TILE_LAYOUT): weight = weight.T.contiguous() weight = ttnn.from_torch(weight, dtype=dtype, layout=layout) return weight
I'm trying to understand the functionality of conv2d and how it implements a 2D convolution. I think I have the correct tensor shapes (at least no shape or dimension errors are thrown) but I don't understand what is being computed. For a simple 3x3 kernel on a 32x32 matrix (batches=1, channels=1) I expected the following to generate a 1x1x32x32 tensor. Rather the result shape is 1x1x1024x1[32] and, given an input matrix and kernel of
ones
, the result tensor does not have the expected values. What is the required input geometries and values for ?The printed result is