uncomplicate / deep-diamond

A fast Clojure Tensor & Deep Learning library
https://aiprobook.com
Eclipse Public License 1.0
432 stars 17 forks source link

cannot get simple neanderthal code working when using deep-diamond #22

Closed behrica closed 5 months ago

behrica commented 6 months ago

By using uncomplicate/deep-diamond {:mvn/version "0.27.0"} as deps in my project, I cannot get neanderthal working.

(use '[uncomplicate.neanderthal core native])

fails with

Execution error (ArithmeticException) at java.lang.Math/toIntExact (Math.java:1371).
integer overflow
behrica commented 6 months ago

I put all in a repro here: https://github.com/scicloj/scicloj.ml.deep-diamond/tree/2055410ba146613dfe9904457d1f99174bc8238d

Running "clj src/scicloj/ml/deep_diamond/core.clj " inside the dev container environment fails as above

MKL as such seems to work, this passes: https://github.com/scicloj/scicloj.ml.deep-diamond/blob/2055410ba146613dfe9904457d1f99174bc8238d/testMKL/DGEMMExample.java

This can be reproduced open the Git Repo above "as codespaces", for example.

behrica commented 6 months ago

I found the solution , which is to set those:

(set! *warn-on-reflection* true)
(set! *assert* false)
(set! *unchecked-math* :warn-on-boxed)
(set! *print-length* 16)

as the hello world project does. Is this expected ?

behrica commented 6 months ago

So this fails:

clj -Sdeps '{:deps {uncomplicate/neanderthal {:mvn/version "0.48.0"} org.bytedeco/mkl$linux-x86_64-redist {:mvn/version "2024.0-1.5.10"}} org.bytedeco/mkl {:mvn/version "2024.0-1.5.10"}}' -e "(use '[uncomplicate.neanderthal core native])"

while this works:

clj -Sdeps '{:deps {uncomplicate/neanderthal {:mvn/version "0.48.0"} org.bytedeco/mkl$linux-x86_64-redist {:mvn/version "2024.0-1.5.10"}} org.bytedeco/mkl {:mvn/version "2024.0-1.5.10"}}' -e "(set! *unchecked-math* :warn-on-boxed)(use '[uncomplicate.neanderthal core native])"
blueberry commented 6 months ago

Is this issue related to Deep Diamond or Neanderthal?

behrica commented 6 months ago

Related do Deep Diamond. I tried to get neanderthal code working in Deep Diamond. But It fails on importing neanderthal ns.

blueberry commented 6 months ago

I'm asking because in the last listing I can't see reference to Deep Diamond, only Neanderathal.

So, to be precise: Neanderthal 0.48.0 on itself is working for you?

blueberry commented 6 months ago

Can you please try to use leiningen and use deep diamond dev dependency as a guide to your isolated hello world (without other libraries), so we can locate the problem?

behrica commented 6 months ago

I think this is the same as my issue: https://app.slack.com/client/T03RZGPFR/C08PLCRGT

behrica commented 6 months ago

The neanderthal "hello world"

works in my environment, when leaving as-is. https://github.com/uncomplicate/neanderthal/tree/master/examples/hello-world

behrica commented 6 months ago

The moment I remove the global var: unchecked-math :warn-on-boxed

it fails, so the following project.clj does not work for me in the hello world:

(defproject hello-world "0.48.0"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.11.1"]
                 [uncomplicate/neanderthal "0.48.0"]
                 [org.bytedeco/mkl "2024.0-1.5.10" :classifier linux-x86_64-redist]
                 [org.bytedeco/cuda "12.3-8.9-1.5.10" :classifier linux-x86_64-redist]
                 ;; On windows, replace the last two lines with:
                 ;;[org.bytedeco/mkl "2024.0-1.5.10" :classifier windows-x86_64-redist]
                 ;;[org.bytedeco/cuda "12.3-8.9-1.5.10" :classifier windows-x86_64-redist]
                 ]

  ;; :jvm-opts ^:replace ["-Dclojure.compiler.direct-linking=true"
  ;;                      "-XX:MaxDirectMemorySize=16g" "-XX:+UseLargePages"]

  :global-vars {*warn-on-reflection* true
                *assert* false
                ;; not setting *unchecked-math* :warn-on-boxed
                *print-length* 16})
behrica commented 6 months ago

Same behaviour with my code based on deps.edn. The following does work, while I keep setting :unckecked-math to :warn-on-boxed Without it, it fails with "integer overflow" on the "(use ..)" line.

(ns scicloj.ml.deep-diamond.core)

(set! *unchecked-math* :warn-on-boxed)

(use '[uncomplicate.neanderthal core native])

(def x (dv 1 2 3))
(def y (dv 10 20 30))
(dot x y)
blueberry commented 6 months ago

Hmm... I am not able to reproduce it. Do you have another machine available where you could try it? Maybe it's related to your specific environment?

blueberry commented 6 months ago

Can you please try adding

:jvm-opts ^:replace ["-Dclojure.compiler.direct-linking=true"]

It is related to reflection warnings, but might be somehow connected, so it's worth trying...

behrica commented 6 months ago

I tried it, makes no difference.

blueberry commented 5 months ago

Fixed in 0.28.1.