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

[WIP] From ONNX Mode #156

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
8ca9c14
[Refactor] Renamed inv -> reciprocal and unified the definition of ar…
hikettei May 24, 2024
1044cea
[Refactor] Fixed typos: leaky_relu, etc.
hikettei May 24, 2024
8a87f92
[Refactor] Removed scalarXXX impls
hikettei May 24, 2024
5a604dd
fix typo: inv -> reciprocal
hikettei May 24, 2024
e2c50e0
refactor: arithmetic ops, hw-independent tests
hikettei May 24, 2024
7d06b41
[refactor] fixed typo in in-place
hikettei May 25, 2024
021dcfe
fixed issues related to broadcasting and reshaping/bviewing
hikettei May 25, 2024
379c32d
passing all tests
hikettei May 25, 2024
6bbad2e
[Refactor] Updated Command Line developing tools
hikettei May 25, 2024
3478d09
[Refator] Make all tests hardware independent, and uses from fiveam t…
hikettei May 25, 2024
67d8070
[Refactor] Updated the documentation
hikettei May 25, 2024
7fd3e64
updated the badge
hikettei May 25, 2024
541819c
[Refactor] Added demonstration calling from command line tool
hikettei May 25, 2024
b58cc79
[Enhancement] Added an ansi-colored timestamp and info system
hikettei May 25, 2024
42bcaaf
[Workflow] Uses different cases for different hardware, added classif…
hikettei May 25, 2024
32bb564
Merge branch 'develop', remote-tracking branch 'origin' into refactor
hikettei May 25, 2024
ed3ce05
[Workflow] Fixed indentation
hikettei May 25, 2024
60b62f5
[Enhancement] added --config options, mlp generates a file which reco…
hikettei May 25, 2024
f2cb2a3
[Workflow] Installing SIMD Extension, checking accuracy, et al.
hikettei May 25, 2024
eb94aba
[Workflow] Added sudo
hikettei May 25, 2024
8b1e609
[Workflow] Removed Installing Extension step
hikettei May 25, 2024
3f252df
[Workflow] epoch-num=2
hikettei May 25, 2024
55121d7
Update test_on_push.yml
hikettei May 25, 2024
054524f
Merge pull request #153 from hikettei/refactor
hikettei May 25, 2024
1ebff72
[Feature] Get ready for implementing aten backend.
hikettei May 29, 2024
85230ba
[Enhancement] Implemented a baseline for implementing the aten backend
hikettei May 30, 2024
5c93432
[Add] Unary ops
hikettei May 30, 2024
3b02eae
[Enhancement] Parameterized Backend Configuration using symbol-macro
hikettei May 30, 2024
c4d8537
[Update] Aten backends require first call (Aten[Backend] ...) macro.
hikettei May 30, 2024
0999905
[BugFix] Fixed indexing-rule, enabling all permutation tests passed o…
hikettei Jun 1, 2024
75487a4
[BugFix] fixed stride computation to work complicated permutation
hikettei Jun 1, 2024
cadbc25
[Enhancement] DynamicShape for Aten Runtime
hikettei Jun 1, 2024
19a2ad9
Add: nn.lisp
hikettei Jun 1, 2024
863a1d2
[Refactor] Purged JITCPUTensor backend.
hikettei Jun 1, 2024
90c001e
[Enhancement] Supports for configurated runtime declaration
hikettei Jun 1, 2024
10d94b1
Tweaked the example for mnist demonstration get worked again, includi…
hikettei Jun 2, 2024
0a80373
[Optimization] Reduced the number of invoking gcc; by enabling lazy-c…
hikettei Jun 2, 2024
22acca5
[BugFix] Stride Error
hikettei Jun 3, 2024
212d30e
[BugFix] adding initial_offset when using Aten runtime
hikettei Jun 3, 2024
0d532bb
Merge pull request #155 from hikettei/aten-runtime
hikettei Jun 3, 2024
d7be015
[Enhancement] Added: lazy-values. build/proceed bundles multiple DAGs…
hikettei Jun 4, 2024
f789cae
[Add] cl-waffe2.frontend
hikettei Jun 4, 2024
152a283
[Feature] cl-waffe2.frontend was born
hikettei Jun 4, 2024
f8599d1
[Experimental] From ONNX to WFIR Converter
hikettei Jun 4, 2024
29ce500
[Feature] Add Gemm Translation Pattern
hikettei Jun 4, 2024
c7674ab
[Enhancement] New ops: Conv
hikettei Jun 6, 2024
5831de4
[Enhancement] Lazy Computation for padding
hikettei Jun 6, 2024
48240d4
[Enhancement] Dynamic shape computation for imXXX ops
hikettei Jun 6, 2024
e2301a3
[Enhancement] Added LazyAssertion
hikettei Jun 6, 2024
1f667bb
[Enhancement] Various new features including dynamic shaped tensor su…
hikettei Jun 8, 2024
be13af4
ready for implementing yolov3
hikettei Jun 8, 2024
d525492
[BugFix] Fixed Conv2D Shape Infer
hikettei Jun 8, 2024
a17d9d8
[Add] Avgpool
hikettei Jun 8, 2024
da3921c
Various changes
hikettei Jun 9, 2024
78a5396
[WIP] Only the well tested opset converter alives in the code
hikettei Jun 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 94 additions & 5 deletions .github/workflows/test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ on:
- develop

jobs:
test:
name: ${{ matrix.lisp }} on ${{ matrix.os }}
# TODO: Metal/CUDA Runtime
UnitTest-CPUTensor:
# TODO: Metal/CUDA Runtime
name: (${{ matrix.os }} on ${{ matrix.lisp }}) | Unittest-CPUTensor
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -36,10 +38,97 @@ jobs:
- name: Check $PATH
run: echo $PATH

- name: Downloading OpenBLAS
- name: Installing OpenBLAS
run: |
sudo apt install libblas-dev
- name: Operating tests

#- name: Installing Extensions
# run: |
# git submodule update --init --recursive
# sudo make build_sleef
# sudo make build_simd_extension

- name: Unittest (CPU+Lisp)
run: |
ros config set dynamic-space-size 4gb
ros --eval '(progn (defparameter cl-user::*cl-waffe-config* `((:libblas "libblas.so"))))' ./roswell/cl-waffe2-test.ros
./roswell/waffe2.ros test -b CPUTensor -b LispTensor
UnitTest-LispTensor:
name: (${{ matrix.os }} on ${{ matrix.lisp }}) | Unittest-LispTensor
runs-on: ${{ matrix.os }}
strategy:
matrix:
lisp: [sbcl-bin/2.3.9]
os: [ubuntu-latest]
target:
- normal

steps:
- uses: actions/checkout@v1
- name: Setting up environments
env:
LISP: ${{ matrix.lisp }}
run: |
curl -L https://raw.githubusercontent.com/roswell/roswell/master/scripts/install-for-ci.sh | sh
- name: Update $PATH
run: |
echo $PATH
echo "PATH=$HOME/bin:$PATH" >> $GITHUB_ENV
- name: Check $PATH
run: echo $PATH
- name: Unittest (Lisp+CPU)
run: |
ros config set dynamic-space-size 4gb
./roswell/waffe2.ros test -b LispTensor -b CPUTensor
Test-Classification-CPU:
name: (${{ matrix.os }} on ${{ matrix.lisp }}) | Test-Classification-CPU
runs-on: ${{ matrix.os }}
strategy:
matrix:
lisp: [sbcl-bin/2.3.9]
os: [ubuntu-latest]
target:
- normal
archcpu:
- AVX2
steps:
- uses: actions/checkout@v1
- name: Setting up environments
env:
LISP: ${{ matrix.lisp }}
run: |
curl -L https://raw.githubusercontent.com/roswell/roswell/master/scripts/install-for-ci.sh | sh
- name: Update $PATH
run: |
echo $PATH
echo "PATH=$HOME/bin:$PATH" >> $GITHUB_ENV
- name: Check $PATH
run: echo $PATH
- name: Installing OpenBLAS
run: |
sudo apt install libblas-dev

- name: Set up Python
id: set_up_python_python_ci
uses: actions/setup-python@v4
with:
python-version: "3.8"

- name: Downloading assets
run: |
pip install torch torchvision numpy
cd ./examples/mnist
python train_data.py
cd ../../

#- name: Installing Extensions
# run: |
# git submodule update --init --recursive
# sudo make build_sleef
# sudo make build_simd_extension

- name: Training w/ LispTensor
run: |
ros config set dynamic-space-size 4gb
./roswell/waffe2.ros demo --example mnist -b LispTensor -b CPUTensor --config epoch-num=2


20 changes: 11 additions & 9 deletions GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
ROSWELL := ros
SBCL := sbcl
# Avoid loading system-wide libraries (--no-sysinit)
SBCL_OPTIONS := --noinform --no-sysinit
QUICKLOAD_WAFFE2 := --load cl-waffe2.asd --eval '(ql:quickload :cl-waffe2)'
ROSWELL_OPTIONS := dynamic-space-size=4096
QUICKLOAD_WAFFE2 := --eval '(load "cl-waffe2.asd")' --eval '(ql:quickload :cl-waffe2)'
MKTEMP := mktemp
RLWRAP := rlwrap
LOGFILE := $(shell mktemp)
Expand All @@ -26,32 +28,32 @@ compile: ## Compiles the whole project

.PHONY: test
test: ## Running a test harness
$(SBCL) $(SBCL_OPTIONS) $(QUICKLOAD_WAFFE2) \
$(ROSWELL) run $(ROSWELL_OPTIONS) $(QUICKLOAD_WAFFE2) \
--eval '(asdf:test-system :cl-waffe2)' \
--quit

.PHONY: recordtest
recordtest: ## Running a test harness with recording logs
$(warning This session will be recorded in $(LOGFILE))
$(RLWRAP) --logfile $(LOGFILE) \
$(SBCL) $(SBCL_OPTIONS) $(QUICKLOAD_WAFFE2) \
$(ROSWELL) run $(ROSWELL_OPTIONS) $(QUICKLOAD_WAFFE2) \
--eval '(asdf:test-system :cl-waffe2)' \
--quit
@printf 'This session has been recorded in %s\n' $(LOGFILE)

.PHONY: repl
repl: ## Launch REPL with loading cl-waffe2
$(SBCL) $(SBCL_OPTIONS) $(QUICKLOAD_WAFFE2)
$(ROSWELL) run $(ROSWELL_OPTIONS) $(QUICKLOAD_WAFFE2)

.PHONY: rlrepl
rlrepl: ## Launch REPL with rlwrap
$(RLWRAP) $(SBCL) $(SBCL_OPTIONS) $(QUICKLOAD_WAFFE2)
$(RLWRAP) $(ROSWELL) run $(ROSWELL_OPTIONS) $(QUICKLOAD_WAFFE2)

.PHONY: record
record: ## Launch REPL with logging
$(warning This session will be recorded in $(LOGFILE))
$(RLWRAP) --logfile $(LOGFILE) \
$(SBCL) $(SBCL_OPTIONS) $(QUICKLOAD_WAFFE2)
$(ROSWELL) run $(ROSWELL_OPTIONS) $(QUICKLOAD_WAFFE2)
@printf 'This session has been recorded in %s\n' $(LOGFILE)

.PHONY: slynk
Expand All @@ -68,7 +70,7 @@ swank: ## Launch Swank server

.PHONY: docs
docs: ## Generate documents
$(SBCL) $(SBCL_OPTIONS) $(QUICKLOAD_WAFFE2) \
$(ROSWELL) run $(ROSWELL_OPTIONS) $(QUICKLOAD_WAFFE2) \
--eval '(ql:quickload :cl-waffe2/docs)' \
--eval '(cl-waffe2.docs:generate)' \
--quit
Expand Down Expand Up @@ -139,14 +141,14 @@ download_assets: ## Downloads training data sample codes use.

.PHONY: example_mnist
example_mnist: ## Start MNIST Example and Benchmarking. (download_assets must be called in advance)
$(SBCL) $(SBCL_OPTIONS) \
$(ROSWELL) run $(ROSWELL_OPTIONS) \
--load ./cl-waffe2.asd --load ./examples/mnist/mnist.asd \
--eval '(ql:quickload :mnist-sample)' \
--eval '(mnist-sample::train-and-valid-mlp :epoch-num 10)'

.PHONY: example_gpt
example_gpt: ## Launch GPT2 Inference (download_assets must be called in advance)
$(SBCL) --dynamic-space-size 4096 $(SBCL_OPTIONS) \
$(ROSWELL) run $(ROSWELL_OPTIONS) \
--load ./cl-waffe2.asd --load ./examples/gpt-2/gpt-2.asd \
--eval '(ql:quickload :gpt-2-example)' \
--eval '(gpt-2-example:launch-repl)'
Expand Down
40 changes: 6 additions & 34 deletions cl-waffe2.asd
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
:closer-mop
:trivial-garbage
:cl-waffe2/simd-extension

:cl-environments
:numpy-file-format
:jonathan)
Expand Down Expand Up @@ -158,20 +157,7 @@
(:file "package")


(:file "backends/lisp/wf2model")
(:file "backends/JITCPUTensor/package")
(:file "backends/JITCPUTensor/tensor")
(:file "backends/JITCPUTensor/compiler")
(:file "backends/JITCPUTensor/blueprint")
(:file "backends/JITCPUTensor/ir")
(:file "backends/JITCPUTensor/on-finalizing")
(:file "backends/JITCPUTensor/dtype")
(:file "backends/JITCPUTensor/foreign-function")


(:file "backends/JITCPUTensor/impls/arithmetic")
(:file "backends/JITCPUTensor/impls/math")

(:file "backends/lisp/wf2model")
(:file "optimizers/defoptimizer")

(:file "array-converter")
Expand Down Expand Up @@ -223,7 +209,7 @@
:description "Tests for cl-waffe2"
:serial t
:pathname "source"
:depends-on (:cl-waffe2 :fiveam)
:depends-on (:cl-waffe2 :fiveam :rove)
:components ((:file "vm/iterator/test-suites")
(:file "vm/t/package")
(:file "vm/t/lazy-axis")
Expand Down Expand Up @@ -251,30 +237,16 @@
(:file "backends/cpu/t/arithmetic")

(:file "backends/lisp/t/package")

(:file "backends/JITCPUTensor/t/package")
(:file "backends/JITCPUTensor/t/jit")

(:file "nn/t/package")
(:file "nn/t/conv")
(:file "nn/t/activation")
(:file "nn/t/criterion")
(:file "nn/t/regression")
(:file "nn/t/regression")

(:file "test-suites")
)
:perform (test-op (o s)
(symbol-call :fiveam :run! :iterator-test)
(symbol-call :fiveam :run! :test-nodes)
(symbol-call :fiveam :run! :test-tensor)

(symbol-call :fiveam :run! :base-impl-test)
(symbol-call :fiveam :run! :jit-lisp-test)

(symbol-call :fiveam :run! :lisp-backend-test)
(symbol-call :fiveam :run! :test-backends-cpu)
(symbol-call :fiveam :run! :jit-cpu-test)

(symbol-call :fiveam :run! :nn-test)
(symbol-call :fiveam :run! :vm-test)))
:perform (test-op (o s) (error "moved to source/test-suites.lisp")))


(defpackage :cl-waffe2-docs-asdf
Expand Down
30 changes: 30 additions & 0 deletions cl-waffe2.frontends.asd
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

;; [WIP] Feature roadmap on frontends.
;;
;; frontend/onnx (From ONNX To cl-waffe2 translator)
;; frontend/qnn (Quantized Neural Network Op Supports (basically relies on JITCompiler))
;; frontend/backends
;; frontend/backends/cuda (Additional backends which requires more dependency, should be placed at frontend)
;;

(asdf:defsystem :cl-waffe2.frontends
:description "A set of frontend toolkits for cl-waffe2"
:author "hikettei <[email protected]>"
:Licence "MIT")

(asdf:defsystem :cl-waffe2.frontends/onnx
:description "ONNX Graph Translator"
:author "hikettei <[email protected]>"
:licence "MIT"
:pathname "frontends/onnx"
:depends-on ("cl-onnx" "alexandria")
:components ((:file "package")
(:file "utils")
(:file "opset")
(:file "from-model-proto")))

;; Other frontend system follows...
;;(asdf:defsystem :cl-waffe2.frontends/qnn
;; :description "[WIP] Quantization Tools"
;; :author "hikettei <[email protected]>"
;; :licence "MIT")
6 changes: 3 additions & 3 deletions docs/apis/nn.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
(with-example
"(proceed (!sigmoid (randn `(10 10))))"))

(with-nn-doc '!leakey-relu 'function
(with-nn-doc '!leaky-relu 'function
(with-example
"(proceed (!leakey-relu (randn `(10 10))))"))
"(proceed (!leaky-relu (randn `(10 10))))"))

(with-nn-doc '!elu 'function
(with-example
"(proceed (!leakey-relu (randn `(10 10))))"))
"(proceed (!elu (randn `(10 10))))"))

(with-nn-doc '!softmax 'function
(with-example
Expand Down
41 changes: 1 addition & 40 deletions docs/apis/reference.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ The package `cl-waffe2/vm` is the central of system, and features are focused on
(nodedoc SubNode)
(nodedoc MulNode)
(nodedoc DivNode)

(nodedoc InverseTensorNode)

(nodedoc ScalarAdd)
(nodedoc ScalarSub)
(nodedoc ScalarMul)
(nodedoc ScalarDiv)

(nodedoc MoveTensorNode)

Expand Down Expand Up @@ -158,7 +151,7 @@ The package `cl-waffe2/vm` is the central of system, and features are focused on
(caller-doc !matrix-mul)
(caller-doc !matrix-div)

(caller-doc !inverse)
(caller-doc !reciprocal)
(caller-doc !scalar-add)
(caller-doc !scalar-sub)
(caller-doc !scalar-mul)
Expand Down Expand Up @@ -337,35 +330,3 @@ To get further performance on CPU, SIMD Extension must be installed on your devi
,@body)))
(with-op-doc (find-class 'CPUTensor) 't)))

(with-page *cpu-jit-tensor-backend* "[backend] :cl-waffe2/backends.jit.cpu"
(insert "
Those backends without JIT, relies on `do-compiled-loop` or `call-with-view` to calculate only part of matrices: complicated offsets and permution (i.e: `!view` and `!permute`). However, under certain circumstances this can be difficult to parallelise by simply calling a CFFI function; and this backend is intended to solve the problem.

This package provides a `JITCPUTensor` backend which works by jit-compiling whole code to vectorized C, and is only for the purpose of optimising memory layout, so currently only four arithmetic operations and copying are implemented. (OpFusion is remained to be implemented; but it is definitely possible to fuse several ops)

Optimise the memory layout by enclosing the code you want to optimise the layout in:

```lisp
(with-cpu-jit (CPUTensor LispTensor)
;; body
)
```

Tips: Use the `proceed-bench` function to know the bottleneck; if `MoveTensorNode` combined with `PermuteNode` is slow compared to other nodes, the memory layout is remained to be optimized for example.
")

(macrolet ((with-op-doc (name type &body body)
`(progn
(placedoc ,name ,type)
,@body)))
(with-op-doc '*default-c-compiler* 'variable)
(with-op-doc '*compiler-flags* 'variable)
(with-op-doc '*viz-compiled-code* 'variable)

(with-op-doc (find-class 'JITCPUTensor) 't)

(with-op-doc #'cpujit-set-config 'function)
(with-op-doc (macro-function 'with-cpu-jit) 'function)

))

Loading
Loading