コード例 #1
0
def main():
    device = torch_mlir.mlir_device()
    model = Net()
    tensor = torch.randn((64, 1, 28, 28), requires_grad=True)
    # CHECK: PASS! fwd check
    fwd_path = test.check_ref(model, tensor)

    target = torch.ones((64), dtype=torch.long)
    loss = F.nll_loss

    # CHECK: PASS! back check
    test.check_back(fwd_path, target, loss)

    # CHECK: PASS! fc1_weight_grad check
    test.compare(model.fc1.weight.grad, fwd_path[0].fc1.weight.grad,
                 "fc1_weight_grad")
コード例 #2
0
def main():
    model = Net()
    tensor = torch.randn((64, 1, 28, 28), requires_grad=True)

    # CHECK: PASS! fwd check
    fwd_path = test.check_fwd(model, tensor)

    target = torch.ones((64), dtype=torch.long)
    loss = F.nll_loss

    # CHECK: PASS! back check
    test.check_back(fwd_path, target, loss)

    # CHECK: PASS! weight_grad check
    test.compare(model.conv2.weight.grad, fwd_path[0].conv2.weight.grad,
                 "weight_grad")
    # CHECK: PASS! bias_grad check
    test.compare(model.conv2.bias.grad, fwd_path[0].conv2.bias.grad,
                 "bias_grad")
    # CHECK: PASS! fc1_weight_grad check
    test.compare(model.fc1.weight.grad, fwd_path[0].fc1.weight.grad,
                 "fc1_weight_grad")
コード例 #3
0
# -*- Python -*-
# This file is licensed under a pytorch-style license
# See frontends/pytorch/LICENSE for license information.

import torch
import npcomp.frontends.pytorch as torch_mlir
import npcomp.frontends.pytorch.test as test

# RUN: %PYTHON %s | FileCheck %s

model = torch.nn.LogSoftmax(dim=1)
tensor = torch.randn(3, 5, requires_grad=True)

# CHECK: PASS! fwd check
fwd_path = test.check_fwd(model, tensor)

target = torch.tensor([1, 0, 4])
loss = torch.nn.NLLLoss()

# CHECK: PASS! back check
test.check_back(fwd_path, target, loss)