예제 #1
0
        preProbSquared = x * x
        l1loss = torch.sum(0.01 * torch.abs(preProbSquared))

        window_size = (int(x.size()[2]), int(x.size()[3]))
        x = torch.nn.functional.avg_pool2d(x, kernel_size=window_size)
        x = torch.squeeze(x)
        probs = self.softmax(x)
        logprobs = torch.log(probs)
        nll = nllloss(logprobs, labels)

        loss = l1loss + nll
        return loss


# Set arbitrary seed so model weights are initialized to the
# same values each time the test is run
torch.manual_seed(1)

torchWriter = torchwriter.PytorchNetWriter(
    inNames=inNames,
    outNames=outNames,
    optimizer=popart.ConstSGD(0.001),
    inputShapeInfo=inputShapeInfo,
    dataFlow=dataFlow,
    ### Torch specific:
    module=Module0(),
    samplesPerBatch=batchSize)

c10driver.run(torchWriter, willowOptPatterns, args.outputdir, cifarInIndices,
              args.device, args.hw_id)
예제 #2
0
        b = i[0:1].view(3, 1, 4)

        h0 = b[0:1, 0:4].view(1, 1, 4)
        c0 = b[1:2, 0:4].view(1, 1, 4)
        x = self.lstm(a, (h0, c0))
        result = torch.cat((x[0], x[1][0], x[1][1]))
        l1loss = torch.sum(0.1 * torch.abs(result))

        return l1loss


# Set arbitrary seed so model weights are initialized to the
# same values each time the test is run
torch.manual_seed(1)

torchWriter = torchwriter.PytorchNetWriter(
    inNames=inNames,
    outNames=outNames,
    optimizer=popart.ConstSGD(0.001),
    inputShapeInfo=inputShapeInfo,
    dataFlow=dataFlow,
    ### Torch specific:
    module=Module0(),
    samplesPerBatch=batchSize)

c10driver.run(
    torchWriter,
    popart.Patterns(['PreUniRepl', 'MulArgGradOp', 'AbsGradOp',
                     'OpToReshape']), args.outputdir, cifarInIndices,
    args.device, args.hw_id)
예제 #3
0
                                     stride=1,
                                     padding=(1, 3),
                                     bias=False)
        self.relu = torch.nn.functional.relu

    def forward(self, inputs):
        """out = l1loss(relu(conv(in)))"""
        image0 = inputs[0]
        x = self.conv1(image0)
        x = self.relu(x)
        x = torch.sum(0.1 * torch.abs(x))  # l1loss
        return x


# Set arbitrary seed so model weights are initialized to the
# same values each time the test is run
torch.manual_seed(1)

torchWriter = torchwriter.PytorchNetWriter(
    inNames=inNames,
    outNames=outNames,
    optimizer=popart.ConstSGD(0.001),
    inputShapeInfo=inputShapeInfo,
    dataFlow=dataFlow,
    ### Torch specific:
    module=Module0(),
    samplesPerBatch=batchSize)

c10driver.run(torchWriter, None, args.outputdir, cifarInIndices, args.device,
              args.hw_id)
예제 #4
0
    def forward(self, inputs):
        """out = relu(conv(in))"""
        image0 = inputs[0]
        x = self.conv1(image0)
        x = self.relu(x)
        return x


# Set arbitrary seed so model weights are initialized to the
# same values each time the test is run
torch.manual_seed(1)

torchWriter = torchwriter.PytorchNetWriter(
    inNames=inNames,
    outNames=outNames,
    optimizer=optimizer,
    inputShapeInfo=inputShapeInfo,
    dataFlow=dataFlow,
    ### Torch specific:
    module=Module0(),
    samplesPerBatch=samplesPerBatch)

# Passes if torch and popart models match
c10driver.run(torchWriter=torchWriter,
              patterns=None,
              outputdir=args.outputdir,
              cifarInIndices=cifarInIndices,
              device=args.device,
              device_hw_id=args.hw_id,
              mode="infer")
예제 #5
0
        im0 = inputs[0]
        x = self.conv1(im0)
        x = self.in2(x)
        x = self.sin(x)
        return x


# Set arbitrary seed so model weights are initialized to the
# same values each time the test is run
torch.manual_seed(1)

torchWriter = torchwriter.PytorchNetWriter(
    inNames=inNames,
    outNames=outNames,
    losses=losses,
    optimizer=popart.ConstSGD(0.001),
    inputShapeInfo=inputShapeInfo,
    dataFlow=dataFlow,
    ### Torch specific:
    module=Module0(),
    samplesPerBatch=batchSize)

c10driver.run(torchWriter,
              None,
              args.outputdir,
              cifarInIndices,
              args.device,
              args.hw_id,
              transformations=["prepareNodesForTraining"],
              epochs=4)
예제 #6
0
파일: model1.py 프로젝트: 546287123/popart
        # print(x.shape, inputs[2].shape)
        loss = nllloss(probs, inputs[2])
        return loss


# Set arbitrary seed so model weights are initialized to the
# same values each time the test is run
torch.manual_seed(1)

torchWriter = torchwriter.PytorchNetWriter(
    inNames=inNames,
    outNames=outNames,
    optimizer=popart.ConstSGD(0.001),
    inputShapeInfo=inputShapeInfo,
    dataFlow=dataFlow,
    ### Torch specific:
    module=Module0(),
    samplesPerBatch=batchSize)

# As part of T16818 (model indeterminism) it is useful to
# intercept the output directory here with something like
#args.outputdir="/path/to/logging/dir/where/models/written/"

c10driver.run(torchWriter,
              willowOptPatterns,
              args.outputdir,
              cifarInIndices,
              args.device,
              args.hw_id,
              printAnchorArrays=True)
예제 #7
0
        # seq_length 3
        # batch_size 1
        # input_size 4
        a = i[0:1].view(3, 1, 4)
        b = i[0:1].view(3, 1, 4)

        h0 = b[0:1, 0:4].view(1, 1, 4)
        c0 = b[1:2, 0:4].view(1, 1, 4)
        x = self.lstm(a, (h0, c0))
        result = x[0]
        return result


# Set arbitrary seed so model weights are initialized to the
# same values each time the test is run
torch.manual_seed(1)

torchWriter = torchwriter.PytorchNetWriter(
    inNames=inNames,
    outNames=outNames,
    losses=losses,
    optimizer=popart.ConstSGD(0.001),
    inputShapeInfo=inputShapeInfo,
    dataFlow=dataFlow,
    ### Torch specific:
    module=Module0(),
    samplesPerBatch=batchSize)

c10driver.run(torchWriter, popart.Patterns(['PreUniRepl']), args.outputdir,
              cifarInIndices, args.device, args.hw_id)
예제 #8
0
# Set arbitrary seed so model weights are initialized to the
# same values each time the test is run
torch.manual_seed(1)

# Test with ConstSGD

anchors_1 = c10driver.run(
    torchwriter.PytorchNetWriter(
        inNames=inNames,
        outNames=outNames,
        losses=losses,
        # default loss scaling (1.0f)
        optimizer=popart.SGD({"defaultLearningRate": (0.001, True)}),
        inputShapeInfo=inputShapeInfo,
        dataFlow=dataFlow,
        ### Torch specific:
        module=Module0(),
        samplesPerBatch=batchSize),
    willowOptPasses,
    args.outputdir,
    cifarInIndices,
    args.device,
    args.hw_id)

# Test with ConstSGD
anchors_2 = c10driver.run(
    torchwriter.PytorchNetWriter(
        inNames=inNames,
        outNames=outNames,
        losses=losses,