Skip to content

Commit

Permalink
Merge pull request #137 from hikettei/cnn-patch
Browse files Browse the repository at this point in the history
[BugFix] Dynamic Shape and LazyAxis Comparison
  • Loading branch information
hikettei authored Oct 16, 2023
2 parents eb46499 + e9cc8a1 commit 4304804
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
6 changes: 2 additions & 4 deletions source/nn/conv.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ Note: When `Conv2D` is initialised, the output is displayed as -1. This is becau
C_in = in-channels
C_out = out-channels
;; H_out = floor(((H_in + 2 * padding[0] - dilation[0] * (kernel_size[0] - 1) - 1) / stride[0]) + 1)
H_out = (floor (+ 1 (/ (+ H_in (* 2 (car padding)) (* (- (car dilation)) (- (car kernel-size) 1)) -1)
(car stride))))
H_out = (conv-out-size H_in (car padding) (car dilation) (car kernel-size) (car stride))
;; W_out = floor(((W_in + 2 * padding[1] - dilation[1] * (kernel_size[1] - 1) - 1) / stride[1]) + 1)
W_out = (floor (+ 1 (/ (+ W_in (* 2 (second padding)) (* (- (second dilation)) (- (second kernel-size) 1)) -1)
(second stride)))))
W_out = (conv-out-size W_in (second padding) (second dilation) (second kernel-size) (second stride)))
:on-call-> apply-conv2d)

(assert (typep kernel-size 'list)
Expand Down
25 changes: 16 additions & 9 deletions source/vm/lazy-subscript.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,22 @@ No macro usings are allowed; functions and fixnum, list are available.
(let* ((lazyir (parse-lazy-exp expression))
(args (ir->args lazyir))
(form (ir->list lazyir)))
(if (and (typep (lazyir-car lazyir) 'fixnum)
(eql (lazyir-type lazyir) :number))
(lazyir-car lazyir)
(%make-lazyaxis
args
lazyir
(if (listp form)
#'(lambda () (interpret-lazy lazyir))
#'(lambda () form))))))

(when (and
(typep (lazyir-car lazyir) 'fixnum)
(eql (lazyir-type lazyir) :number))
(return-from make-lazyaxis (lazyir-car lazyir)))

(when (eql (lazyir-type lazyir) :dynamic-shape)
(return-from make-lazyaxis
(cadr (second (lazyir-car lazyir)))))

(%make-lazyaxis
args
lazyir
(if (listp form)
#'(lambda () (interpret-lazy lazyir))
#'(lambda () form)))))

(defun make-dumpable-lazy-axis (expression)
(let* ((lazyir (parse-lazy-exp expression))
Expand Down
8 changes: 8 additions & 0 deletions source/vm/t/lazy-axis.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,11 @@

;; CNN with activation

(defun lazyaxis-and-symbol-comparison ()
(build (softmax-cross-entropy
(!reshape (call (Conv2D 3 6 `(5 5)) (make-input `(N 3 25 25) :X)) (~ N C H W -> N (* C H W)))
(make-input `(N 2646) :X))))

(test lazyaxis-and-symbol-comparison
(is (lazyaxis-and-symbol-comparison)))

0 comments on commit 4304804

Please sign in to comment.