Skip to content

BasicGradientDescent example crashes #22

Open
@steppity

Description

@steppity

The BasicGradientDescent example is crashing here with EXC_BAD_ACCESS on the first call to the loss function.

This is on an M1 MacBook with:
Xcode: 15.2
Toolchain: Swift Development Snapshot 2024-02-04 (a)

Project setup is via New Project with template MacOS Command Line Tool, then pasting your main.swift over the generated one.
(The other examples build and run correctly with this setup).

For some reason the crash can be fixed by unrolling the loop inside the loss function like this:

var data = andGateData[0]
var prediction = model(data.x1, data.x2)
var error = data.y - prediction
loss = loss + error * error / 2

data = andGateData[1]
prediction = model(data.x1, data.x2)
error = data.y - prediction
loss = loss + error * error / 2

data = andGateData[2]
prediction = model(data.x1, data.x2)
error = data.y - prediction
loss = loss + error * error / 2

data = andGateData[3]
prediction = model(data.x1, data.x2)
error = data.y - prediction
loss = loss + error * error / 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions