Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial bugfixes and CI integration #472

Merged
merged 13 commits into from
Feb 1, 2021
27 changes: 12 additions & 15 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
os: [ubuntu-18.04, macos-latest]
include:
- os: macos-latest
install_deps: brew install llvm@9 pkg-config
install_deps: brew install llvm@9 pkg-config wget gzip
path_extension: $(brew --prefix llvm@9)/bin
- os: ubuntu-18.04
install_deps: sudo apt-get install llvm-9-tools llvm-9-dev pkg-config
install_deps: sudo apt-get install llvm-9-tools llvm-9-dev pkg-config wget gzip
path_extension: /usr/lib/llvm-9/bin

runs-on: ${{ matrix.os }}
Expand All @@ -37,12 +37,22 @@ jobs:
${{ matrix.install_deps }}
echo "${{ matrix.path_extension }}" >> $GITHUB_PATH

- name: Get example files
run: |
wget http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz
wget http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz
gunzip t10k-images-idx3-ubyte.gz t10k-labels-idx1-ubyte.gz
mv t10k-images-idx3-ubyte t10k-labels-idx1-ubyte $GITHUB_WORKSPACE/examples/

- name: Cache
uses: actions/cache@v2
with:
path: |
~/.stack
$GITHUB_WORKSPACE/.stack-work
$GITHUB_WORKSPACE/examples/t10k-images-idx3-ubyte
$GITHUB_WORKSPACE/examples/t10k-labels-idx1-ubyte

key: ${{ runner.os }}-${{ hashFiles('**/*.cabal', 'stack*.yaml') }}
restore-keys: ${{ runner.os }}-

Expand All @@ -57,19 +67,6 @@ jobs:

- name: Build
run: make build

- name: Download MNist files
uses: suisei-cn/actions-download-file@v1
id: mnist
with:
url: "https://github.com/srush/learns-dex/raw/main/mnist.bin"
target: examples/
- name: Download MNist labels file
uses: suisei-cn/actions-download-file@v1
id: labels
with:
url: "https://github.com/srush/learns-dex/raw/main/labels.bin"
target: examples/

- name: Run tests
run: make tests
14 changes: 8 additions & 6 deletions examples/tutorial.dx
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ def tableAdd' (x : m => n => Float32) (y : m => n => Float32) : m => n => Float3

' To run this section, move the following binary files to examples:

' `wget https://github.com/srush/learns-dex/raw/main/mnist.bin`
' `wget http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz; gunzip t10k-images-idx3-ubyte.gz`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't unzip a bit more standard for this? I think it's equivalent to gunzip on most Linuxes, but also works on BSD-based systems (macOS).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, is that true? unzip doesn't seem to work for me linux for .gz files. Also gunzip seems to install fine in the macOS CI test. But I don't have a mac to test on. Does unzip work there?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirm the following works on macOS:

$ wget http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz; gunzip t10k-images-idx3-ubyte.gz
# Produces unzipped t10k-images-idx3-ubyte, 7.5M.

Hope this helps!


' `wget https://github.com/srush/learns-dex/raw/main/labels.bin`
' `wget http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz; gunzip t10k-labels-idx1-ubyte.gz`

' To make some of these concepts for tangible let us consider a real example
using MNist digits. For this example we will first read in a batch of images
Expand All @@ -320,14 +320,16 @@ def pixel (x:Char) : Float32 =
False -> r

def getIm : Batch => Image =
(AsList _ im) = unsafeIO do readFile "examples/mnist.bin"
raw = unsafeCastTable Full im
-- File is unsigned bytes offset with 16 starting bytes
(AsList _ im) = unsafeIO do readFile "examples/t10k-images-idx3-ubyte"
raw = unsafeCastTable Full (for i:Batch. im.((ordinal i + 16) @ _))
for b: Batch i j.
pixel raw.((ordinal (b, i, j)) @ Full)

def getLabel : Batch => Class =
(AsList _ im2) = unsafeIO do readFile "examples/labels.bin"
r = unsafeCastTable Batch im2
-- File is unsigned bytes offset with 8 starting bytes
(AsList _ lab) = unsafeIO do readFile "examples/t10k-labels-idx1-ubyte"
r = unsafeCastTable Batch (for i:Batch. lab.((ordinal i + 8) @ _))
for i. (W8ToI r.i @ Class)

' Once you have downloaded the files, uncomment these lines to
Expand Down