|
| 1 | +;; Copyright (c) Dragan Djuric. All rights reserved. |
| 2 | +;; The use and distribution terms for this software are covered by the |
| 3 | +;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) or later |
| 4 | +;; which can be found in the file LICENSE at the root of this distribution. |
| 5 | +;; By using this software in any fashion, you are agreeing to be bound by |
| 6 | +;; the terms of this license. |
| 7 | +;; You must not remove this notice, or any other, from this software. |
| 8 | + |
| 9 | +(ns ^{:author "Dragan Djuric"} |
| 10 | + orig |
| 11 | + (:require |
| 12 | + [uncomplicate.commons [core :refer [with-release]]] |
| 13 | + [uncomplicate.fluokitten.core :refer [foldmap]] |
| 14 | + [uncomplicate.neanderthal.core :refer [iamax transfer! native view-vctr entry!]] |
| 15 | + [uncomplicate.diamond |
| 16 | + [tensor :refer [tensor output]] |
| 17 | + [dnn :refer [network activation]] |
| 18 | + [onnxrt :refer [onnx]]] |
| 19 | + [uncomplicate.diamond.internal.protocols :refer [neanderthal-factory]] |
| 20 | + [uncomplicate.diamond.internal.onnxrt |
| 21 | + [core :refer [options override-dimension!]]] |
| 22 | + [uncomplicate.diamond.internal.dnnl.factory :refer [dnnl-factory]] |
| 23 | + ;[uncomplicate.diamond.internal.cudnn.factory :refer [cudnn-factory]] |
| 24 | + )) |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +(let [fact (dnnl-factory) |
| 29 | + neand-fact (neanderthal-factory fact)] |
| 30 | + (with-release [opt (-> (options) |
| 31 | + (override-dimension! "batch_size" 1) |
| 32 | + (override-dimension! "sequence_length" 1) |
| 33 | + (override-dimension! "past_sequence_length" 1) |
| 34 | + (override-dimension! "past_sequence_length + 1" 1)) |
| 35 | + src-tz (tensor fact [1 1 28 28] :float :nchw) |
| 36 | + onnx-bp (onnx fact "/tmp/models/HuggingFaceTB/SmolLM-135M/onnx/model.onnx" {:options opt}) |
| 37 | + input-ids (tensor neand-fact [1 1] :long :nc) |
| 38 | + position-ids (tensor neand-fact [1 1] :long :nc) |
| 39 | + attention-mask (tensor neand-fact [1 1] :long :nc) |
| 40 | + past-key-values (repeatedly 60 #(tensor fact [1 3 1 64] :float :nchw)) |
| 41 | + smollm-next! (onnx-bp (into [input-ids attention-mask position-ids] past-key-values))] |
| 42 | + (transfer! [2] input-ids) |
| 43 | + (transfer! [0] position-ids) |
| 44 | + (transfer! [1] attention-mask) |
| 45 | + (doseq [pkv past-key-values] |
| 46 | + (transfer! (repeat 0) pkv)) |
| 47 | + (println |
| 48 | + (take 10 (view-vctr (native (first (smollm-next!)))))))) |
0 commit comments