Skip to content

Commit

Permalink
[Enhancement] added --config options, mlp generates a file which reco…
Browse files Browse the repository at this point in the history
…rds the acc
  • Loading branch information
hikettei committed May 25, 2024
1 parent ed3ce05 commit 60b62f5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
11 changes: 10 additions & 1 deletion examples/mnist/mlp.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,16 @@

(format t "Validating...~%")
(with-no-grad
(format t "Validation Accuracy: ~a~%~%" (accuracy model test-img test-label)))
(let ((acc (accuracy model test-img test-label)))
(format t "Validation Accuracy: ~a~%~%" acc)

;; For github workflow
(with-open-file (str "./report.txt"
:direction :output
:if-exists :supersede
:if-does-not-exist :create)
;;
(format str "~a" acc))))

(when benchmark-p
(format t "Benchmarking (Forward Step, 1Epoch, n-sample=600)...~%")
Expand Down
2 changes: 1 addition & 1 deletion roswell/waffe2.asd
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
:author "hikettei"
:description "Command Line Tool for cl-waffe2"
:licence "MIT"
:depends-on ("cl-waffe2" "clingon" "asdf" "cl-ansi-text")
:depends-on ("cl-waffe2" "clingon" "asdf" "cl-ansi-text" "rove")
:components ((:file "waffe2")))
23 changes: 19 additions & 4 deletions roswell/waffe2.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(progn ;;init forms
(ros:ensure-asdf)
#+quicklisp(cl:push (cl:pathname "./") ql:*local-project-directories*)
#+quicklisp(ql:quickload '(:cl-waffe2 :clingon :cl-ansi-text) :silent t))
#+quicklisp(ql:quickload '(:cl-waffe2 :clingon :rove :cl-ansi-text) :silent t))

(defpackage :waffe2
(:use :cl :cl-ansi-text)
Expand Down Expand Up @@ -44,7 +44,13 @@
(loop for arg in args
for parsed = (uiop:split-string arg :separator "=")
collect (cons (symbol-name (read-from-string (car parsed))) (read-from-string (second parsed))))))
#+(or)(print (parse-test-config "M=1, K=2"))

(defun parse-test-config-kwargs (config)
(let ((args (uiop:split-string config :separator ",")))
(loop for arg in args
for parsed = (uiop:split-string arg :separator "=")
append (list (intern (symbol-name (read-from-string (car parsed))) "KEYWORD") (read-from-string (second parsed))))))
#+(or)(print (parse-test-config-kwargs ""))

(defun str->backend (name)
(let ((available-backends (map 'list #'class-name (alexandria:flatten (cl-waffe2:find-available-backends)))))
Expand All @@ -59,11 +65,13 @@
`(equalp model ,name)))
(cond
((of "mnist")
;; ros config set dynamic-space-size 4gb
(print-info "Loading the example project...")
(load "./examples/mnist/mnist.asd")
(ql:quickload :mnist-sample :silent t)
(print-info "Starting the demonstration...")
(uiop:symbol-call :mnist-sample :train-and-valid-mlp :epoch-num 10))
(apply #'uiop:symbol-call :mnist-sample :train-and-valid-mlp (parse-test-config-kwargs (clingon:getopt cmd :config "")))
(print-info "Completed"))
(T
(error "--example ~a is not available." model))))))

Expand All @@ -79,6 +87,7 @@
(print-info "Running the test...")
(asdf:load-system :cl-waffe2/test)
(uiop:symbol-call :cl-waffe2/tester :running-test :style (intern (string-upcase (clingon:getopt cmd :style "dot")) "KEYWORD"))
(print-info "Completed")
t)
((of "gendoc")
(print-info "Generating the documents...")
Expand Down Expand Up @@ -119,7 +128,13 @@
:description "Enables/Disables the cl-ansi-color"
:short-name #\a
:long-name "ansi-color"
:key :ansi-color)))
:key :ansi-color)
(clingon:make-option
:string
:description "Additional configurations. (e.g.: epoch=10,batch=1)"
:short-name #\c
:long-name "config"
:key :config)))

(defun waffe2/command ()
(clingon:make-command
Expand Down

0 comments on commit 60b62f5

Please sign in to comment.