Skip to content

Commit

Permalink
[Refator] Make all tests hardware independent, and uses from fiveam t…
Browse files Browse the repository at this point in the history
…o rove.
  • Loading branch information
hikettei committed May 25, 2024
1 parent 6bbad2e commit 3478d09
Show file tree
Hide file tree
Showing 26 changed files with 376 additions and 465 deletions.
19 changes: 1 addition & 18 deletions cl-waffe2.asd
Original file line number Diff line number Diff line change
Expand Up @@ -263,24 +263,7 @@

(:file "test-suites")
)
:perform (test-op (o s)
;;(symbol-call :cl-waffe2/tester :running-test (find-symbol "LispTensor"))
#|
(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
23 changes: 17 additions & 6 deletions roswell/waffe2.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,21 @@

(defun waffe2/handler (cmd)
(let* ((backends (or (clingon:getopt cmd :backends) `("LispTensor"))))

;; Configure runtimes toplevel
(apply #'cl-waffe2:set-devices-toplevel (map 'list #'str->backend backends))

(macrolet ((of (name)
`(string= *mode* ,name)))
(cond
((of "test")
(asdf:load-system :cl-waffe2/test)
(uiop:symbol-call :cl-waffe2/tester :running-test)
(uiop:symbol-call :cl-waffe2/tester :running-test :style (intern (string-upcase (clingon:getopt cmd :style "dot")) "KEYWORD"))
t)
((of "gendoc")
(ql:quickload :cl-waffe2/docs :silent t)
(uiop:symbol-call :cl-waffe2.docs :generate)
t)
((of "gencode")
;; WIP From ONNX -> C/C++/CUDA Code generator
;; WIP From ONNX -> C/C++/CUDA Code Generator + Mimimun C Interpreter
(error "Export2Clang Mode is not yet ready.")
t)
(T nil)))))
Expand All @@ -56,7 +54,13 @@
:description "Backend to use (e.g.: $ waffe2 test -b CPUTensor -b LispTensor ...)"
:short-name #\b
:long-name "backend"
:key :backends)))
:key :backends)
(clingon:make-option
:string
:description "Style for the testing tool. One of dot, spec, none. (conform to rove)"
:short-name #\s
:long-name "style"
:key :style)))

(defun waffe2/command ()
(clingon:make-command
Expand All @@ -65,7 +69,14 @@
:authors '("hikettei <ichndm@gmail.com>")
:license "MIT"
:options (waffe2/options)
:usage "[test | gendoc | gencode ] [options]"
:usage "[ unittest | test | gendoc | gencode ] [options]
COMMANDS:
- unittest Tests if all principle abstractnode works given backends.
- test Run all tests under the given backends.
- test[package] Run all tests
- gendoc Generates the cl-waffe2 documentation.
- gencode [WIP] Mimimum C runtime generator (from ONNX)"
:handler #'waffe2/handler))

(defparameter *mode* "")
Expand Down
27 changes: 27 additions & 0 deletions source/backends/lisp/mathematics.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,30 @@

(define-math-impl Log1PNode #'(lambda (x) (log (1+ x))) t)
)

(define-with-typevar (expt-caller u) (n x y offsetx offsety incx incy size)
(declare (optimize (speed 3))
(type (simple-array u (*)) x y)
(type u n)
(type fixnum offsetx offsety incx incy size))
(dotimes (i size)
(setf (aref y (+ offsety (the fixnum (* incy i))))
(expt (aref x (+ offsetx (the fixnum (* incx i)))) n))))

(define-impl (ExptNode
:device LispTensor)
:forward ((self x out n)
(let ((caller (expt-caller (dtype out))))
`(,@(call-with-view
#'(lambda (x-view o-view)
`(funcall ,caller
(tensor-vec ,n)
(tensor-vec ,x)
(tensor-vec ,out)
,(offset-of x-view 0)
,(offset-of o-view 0)
,(stride-of x-view 0)
,(stride-of o-view 0)
,(size-of x-view 0)))
`(,x ,out))
,out))))
2 changes: 1 addition & 1 deletion source/base-impl/fundamental.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ CL-WAFFE2-REPL>
:forward ((self scalar matrix)
`(progn
(tensor-vec ,matrix) ;; Call Lazy-Allocate of matrix
(setf (vref ,matrix 0) (tensor-vec ,scalar))
(setf (vref ,matrix 0) (coerce (tensor-vec ,scalar) (dtype->lisp-type (dtype ,matrix))))
,matrix)))

;; Add: Docstring
Expand Down
9 changes: 4 additions & 5 deletions source/nn/t/activation.lisp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

(in-package :cl-waffe2/nn.test)

(in-suite :nn-test)

(defun relu-test ()
(let ((a (randn `(10 10))))
(let ((out (proceed (!relu a))))
Expand All @@ -14,7 +12,8 @@
(< (abs (- 10.0 (tensor-vec out))) 0.0001))))


(test activation-test
(is (relu-test))
(is (softmax-test)))
(deftest activation-test
(testing "Testing activation functions."
(ok (relu-test))
(ok (softmax-test))))

34 changes: 15 additions & 19 deletions source/nn/t/conv.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
(in-package :cl-waffe2/nn.test)


(in-suite :nn-test)

(defun conv-2d-forward-test ()
(let ((model (Conv2D 3 6 `(2 2))))
(equal `(3 6 9 9) (shape (proceed (call model (randn `(3 3 10 10))))))))
Expand Down Expand Up @@ -57,14 +55,16 @@
#(0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0)
(tensor-vec (grad img)))))

(test conv2d-fw-bw-test
(is (conv-2d-forward-test))
(is (conv-2d-fw-bw-test))
(is (conv-2d-fw-bw-test-1)))
(deftest conv2d-fw-bw-test
(testing "Testing Conv2D Function"
(ok (conv-2d-forward-test))
(ok (conv-2d-fw-bw-test))
(ok (conv-2d-fw-bw-test-1))))

(test im2col-test
(is (unfold-test-forward))
(is (unfold-test-backward)))
(deftest im2col-test
(testing "Testing im2col"
(ok (unfold-test-forward))
(ok (unfold-test-backward))))


;; MaxPoolTest
Expand Down Expand Up @@ -101,14 +101,10 @@

f))

(test 2d-pool-test
(is (2d-pool-test nil))
(is (2d-pool-test t))

;; Do they work even when cached?
(is (2d-pool-test t))
(is (2d-pool-test nil)))

;; Add: CNN/MLP Train tests
(deftest 2d-pool-test
(testing "Testing 2DPool"
(ok (2d-pool-test nil))
(ok (2d-pool-test t))
(ok (2d-pool-test t))
(ok (2d-pool-test nil))))

;; Paddings
18 changes: 8 additions & 10 deletions source/nn/t/criterion.lisp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

(in-package :cl-waffe2/nn.test)

(in-suite :nn-test)

(defun softmax-cross-entropy-test ()
(let ((a (parameter (randn `(10 10))))
(b (parameter (randn `(10 10)))))
Expand All @@ -27,9 +25,10 @@
;; -> error due to MoveTensorNode was ignored.
;; -> self was duplicated in the cached functions.

(test softmax-cross-entropy-and-static-node-backward
(is (softmax-cross-entropy-test))
(is (softmax-cross-entropy-test1)))
(deftest softmax-cross-entropy-and-static-node-backward
(testing "Testing FusedSoftmaxCrossEntropy"
(ok (softmax-cross-entropy-test))
(ok (softmax-cross-entropy-test1))))

(defun criterion-with-build ()
(let ((a (parameter (randn `(10 10))))
Expand All @@ -39,13 +38,12 @@
(forward model)
(backward model)

;;zero-grads! model)
(print (grad a))
(print (grad b))
;; (print (grad a))
;; (print (grad b))

(forward model)
(backward model)

(print (Grad a))
(print (grad b))
;; (print (Grad a))
;; (print (grad b))
)))
7 changes: 1 addition & 6 deletions source/nn/t/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@
:cl-waffe2/backends.cpu
:cl-waffe2/backends.jit.cpu
:cl-waffe2/base-impl
:fiveam
:rove
:cl-waffe2/distributions))

(in-package :cl-waffe2/nn.test)

(def-suite :nn-test)

(in-suite :nn-test)


Loading

0 comments on commit 3478d09

Please sign in to comment.