Skip to content

Commit

Permalink
Add artifact of benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
junjihashimoto committed Nov 6, 2019
1 parent 1a1f55b commit 47de11a
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 31 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/cabal-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@ jobs:
export PATH=/opt/ghc/bin:$PATH
source setenv
cabal v2-test all --jobs=2 --write-ghc-environment-files=always
cabal v2-exec codegen-exe
cabal exec xor-mlp -- +RTS -hc -p
cat xor-mlp.prof
cabal v2-run codegen-exe
cabal v2-run xor-mlp
16 changes: 16 additions & 0 deletions .github/workflows/nix-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,19 @@ jobs:
with:
name: hasktorch
signingKey: '${{ secrets.CACHIX_SIGNING_KEY }}'
- name: Run benchmark
run: |
nix-env -i mnist
ln -s ~/.nix-profile data
nix-build -A hasktorch-examples_cpu ./default.nix
export DEVICE=cpu
export NUM_ITERS=3000
./result/bin/static-mnist-mlp +RTS -hc -p -A128m
cat static-mnist-mlp.prof
mkdir artifact
mv static-mnist-mlp.* artifact
mv loss.html artifact
- uses: actions/upload-artifact@master
with:
name: benchmark
path: artifact
9 changes: 6 additions & 3 deletions .github/workflows/stack-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ jobs:
stack test codegen
stack test libtorch-ffi
stack test hasktorch
stack exec codegen-exe
stack exec xor-mlp -- +RTS -hc -p
cat xor-mlp.prof
stack run codegen-exe
stack run regression
stack run gaussian-process
stack run vae
stack run optimizers
stack run xor-mlp
13 changes: 6 additions & 7 deletions .github/workflows/stack-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ jobs:
stack test codegen
stack test libtorch-ffi
stack test hasktorch
stack exec codegen-exe
stack exec regression
stack exec gaussian-process
stack exec vae
stack exec optimizers
stack exec xor-mlp -- +RTS -hc -p
cat xor-mlp.prof
stack run codegen-exe
stack run regression
stack run gaussian-process
stack run vae
stack run optimizers
stack run xor-mlp
21 changes: 15 additions & 6 deletions examples/static-mnist-cnn/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import System.Random

import qualified ATen.Cast as ATen
import qualified ATen.Class as ATen
import qualified ATen.GC as ATen
import qualified ATen.Type as ATen
import qualified ATen.Managed.Type.Tensor as ATen
import qualified ATen.Managed.Type.Context as ATen
Expand Down Expand Up @@ -115,9 +116,13 @@ instance ( KnownDType dtype
type BatchSize = 512
type TestBatchSize = 8192

train :: forall (device :: (D.DeviceType, Nat)) . _ => IO ()
train = do
let (numIters, printEvery) = (1000000, 250)
train
:: forall (device :: (D.DeviceType, Nat))
. _
=> Int
-> IO ()
train numIters = do
let printEvery = 250
(trainingData, testData) <- I.initMnist
ATen.manual_seed_L 123
init <- A.sample (CNNSpec @ 'D.Float @device)
Expand Down Expand Up @@ -178,9 +183,13 @@ train = do
return (crossEntropyLoss prediction target, errorRate prediction target)

main :: IO ()
main = do
main = ATen.monitorMemory $ do
deviceStr <- try (getEnv "DEVICE") :: IO (Either SomeException String)
numItersStr <- try (getEnv "NUM_ITERS") :: IO (Either SomeException String)
numIters <- case numItersStr of
Right iters -> return $ read iters
_ -> return 1000000
case deviceStr of
Right "cpu" -> train @'( 'D.CPU, 0)
Right "cuda:0" -> train @'( 'D.CUDA, 0)
Right "cpu" -> train @'( 'D.CPU, 0) numIters
Right "cuda:0" -> train @'( 'D.CUDA, 0) numIters
_ -> error "Don't know what to do or how."
18 changes: 12 additions & 6 deletions examples/static-mnist-mlp/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import System.Random

import qualified ATen.Cast as ATen
import qualified ATen.Class as ATen
import qualified ATen.GC as ATen
import qualified ATen.Type as ATen
import qualified ATen.Managed.Type.Tensor as ATen
import qualified ATen.Managed.Type.Context as ATen
Expand Down Expand Up @@ -137,9 +138,10 @@ type HiddenFeatures1 = 256
train
:: forall (device :: (D.DeviceType, Nat))
. _
=> IO ()
train = do
let (numIters, printEvery) = (1000000, 250)
=> Int
-> IO ()
train numIters = do
let printEvery = 250
dropoutProb = 0.5
(trainingData, testData) <- I.initMnist
ATen.manual_seed_L 123
Expand Down Expand Up @@ -210,9 +212,13 @@ train = do
return (crossEntropyLoss prediction target, errorRate prediction target)

main :: IO ()
main = do
main = ATen.monitorMemory $ do
deviceStr <- try (getEnv "DEVICE") :: IO (Either SomeException String)
numItersStr <- try (getEnv "NUM_ITERS") :: IO (Either SomeException String)
numIters <- case numItersStr of
Right iters -> return $ read iters
_ -> return 1000000
case deviceStr of
Right "cpu" -> train @'( 'D.CPU, 0)
Right "cuda:0" -> train @'( 'D.CUDA, 0)
Right "cpu" -> train @'( 'D.CPU, 0) numIters
Right "cuda:0" -> train @'( 'D.CUDA, 0) numIters
_ -> error "Don't know what to do or how."
2 changes: 0 additions & 2 deletions setup-cabal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,4 @@ extra-lib-dirs:
$(pwd)/deps/libtorch/lib
, $(pwd)/deps/mklml/lib
profiling: True
EOF
4 changes: 0 additions & 4 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,3 @@ extra-lib-dirs:

extra-deps:
- template-0.2.0.10@sha256:f822de4d34c45bc84b33a61bc112c15fedee6fa6dc414c62b10456395a868f85

build:
library-profiling: true
executable-profiling: true

0 comments on commit 47de11a

Please sign in to comment.