2025-11-13 21:02.45: New job: test ahrefs/ocannl https://github.com/ahrefs/ocannl.git#refs/heads/master (d856515837ca3e30ee10eb482edbc78ea7469378) (linux-x86_64:(lint-fmt)) Base: ocaml/opam:debian-13-ocaml-4.08@sha256:d8500c15c97ddcfabe40e74b26beae4dbdf65385f70ca81d97f44f1a6556480f ocamlformat version: version 0.28.1 (from opam) To reproduce locally: git clone --recursive "https://github.com/ahrefs/ocannl.git" -b "master" && cd "ocannl" && git reset --hard d8565158 cat > Dockerfile <<'END-OF-DOCKERFILE' FROM ocaml/opam:debian-13-ocaml-4.08@sha256:d8500c15c97ddcfabe40e74b26beae4dbdf65385f70ca81d97f44f1a6556480f USER 1000:1000 RUN cd ~/opam-repository && (git cat-file -e 6c1b38620288b5bf349067f089a7b1fc91185d94 || git fetch origin master) && git reset -q --hard 6c1b38620288b5bf349067f089a7b1fc91185d94 && git log --no-decorate -n1 --oneline && opam update -u RUN opam depext -i dune WORKDIR /src RUN opam depext -i ocamlformat=0.28.1 COPY --chown=1000:1000 . /src/ RUN opam exec -- dune build @fmt --ignore-promoted-rules || (echo "dune build @fmt failed"; exit 2) END-OF-DOCKERFILE docker build . END-REPRO-BLOCK 2025-11-13 21:02.45: Using cache hint "ahrefs/ocannl-ocaml/opam:debian-13-ocaml-4.08@sha256:d8500c15c97ddcfabe40e74b26beae4dbdf65385f70ca81d97f44f1a6556480f-debian-13-4.08_opam-2.4-ocamlformat-6c1b38620288b5bf349067f089a7b1fc91185d94" 2025-11-13 21:02.45: Using OBuilder spec: ((from ocaml/opam:debian-13-ocaml-4.08@sha256:d8500c15c97ddcfabe40e74b26beae4dbdf65385f70ca81d97f44f1a6556480f) (user (uid 1000) (gid 1000)) (run (cache (opam-archives (target /home/opam/.opam/download-cache))) (network host) (shell "cd ~/opam-repository && (git cat-file -e 6c1b38620288b5bf349067f089a7b1fc91185d94 || git fetch origin master) && git reset -q --hard 6c1b38620288b5bf349067f089a7b1fc91185d94 && git log --no-decorate -n1 --oneline && opam update -u")) (run (cache (opam-archives (target /home/opam/.opam/download-cache))) (network host) (shell "opam depext -i dune")) (workdir /src) (run (cache (opam-archives (target /home/opam/.opam/download-cache))) (network host) (shell "opam depext -i ocamlformat=0.28.1")) (copy (src .) (dst /src/)) (run (shell "opam exec -- dune build @fmt --ignore-promoted-rules || (echo \"dune build @fmt failed\"; exit 2)")) ) 2025-11-13 21:02.45: Waiting for resource in pool OCluster 2025-11-13 21:02.45: Waiting for worker… 2025-11-13 21:02.45: Got resource from pool OCluster Building on bremusa.ocamllabs.io HEAD is now at 63eadde4 Add uint32/uint64 precisions and big_models flag for indexing arithmetic HEAD is now at d8565158 Don't guess dim variables as dim-1 prematurely, collab with Claude If the variables participates in a `Total_elems` constraint (currently numerator only), it doesn't need to be guessed so shouldn't. Claude wrote the docs update and helper functions. (from ocaml/opam:debian-13-ocaml-4.08@sha256:d8500c15c97ddcfabe40e74b26beae4dbdf65385f70ca81d97f44f1a6556480f) 2025-11-13 21:02.46 ---> using "8a3fb29dc134ae8cb5011e033937cdf0919031452506a2a7eeab7ea43cc7fe2e" from cache /: (user (uid 1000) (gid 1000)) /: (run (cache (opam-archives (target /home/opam/.opam/download-cache))) (network host) (shell "cd ~/opam-repository && (git cat-file -e 6c1b38620288b5bf349067f089a7b1fc91185d94 || git fetch origin master) && git reset -q --hard 6c1b38620288b5bf349067f089a7b1fc91185d94 && git log --no-decorate -n1 --oneline && opam update -u")) From https://github.com/ocaml/opam-repository * branch master -> FETCH_HEAD 1abfcdbf14..48c9f6e789 master -> origin/master 6c1b386202 Merge pull request #28774 from Julow/release-ocamlformat-0.28.1 <><> Updating package repositories ><><><><><><><><><><><><><><><><><><><><><><> [default] Initialised default (at git+file:///home/opam/opam-repository): [INFO] opam 2.1 and 2.2 include many performance and security improvements over 2.0; please consider upgrading (https://opam.ocaml.org/doc/Install.html) Everything as up-to-date as possible (run with --verbose to show unavailable upgrades). However, you may "opam upgrade" these packages explicitly, which will ask permission to downgrade or uninstall the conflicting packages. Nothing to do. # Run eval $(opam env) to update the current shell environment 2025-11-13 21:03.47 ---> saved as "14a945a064d34712b631e499746c8512ffc2dfe42d633eac294155386c7d69ac" /: (run (cache (opam-archives (target /home/opam/.opam/download-cache))) (network host) (shell "opam depext -i dune")) # Detecting depexts using vars: arch=x86_64, os=linux, os-distribution=debian, os-family=debian # No extra OS packages requirements found. # All required OS packages found. # Now letting opam install the packages The following actions will be performed: - install dune 3.20.2 <><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><><><> [dune.3.20.2] found in cache <><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> -> installed dune.3.20.2 Done. # Run eval $(opam env) to update the current shell environment 2025-11-13 21:04.13 ---> saved as "775944436afef22d875e8871d5f4f1d050a712cc7095353a89b9795804f25edd" /: (workdir /src) /src: (run (cache (opam-archives (target /home/opam/.opam/download-cache))) (network host) (shell "opam depext -i ocamlformat=0.28.1")) # Detecting depexts using vars: arch=x86_64, os=linux, os-distribution=debian, os-family=debian # No extra OS packages requirements found. # All required OS packages found. # Now letting opam install the packages The following actions will be performed: - install sexplib0 v0.14.0 [required by base] - install ocamlbuild 0.16.1 [required by fpath, astring, uuseg] - install either 1.0.0 [required by ocamlformat-lib] - install menhirLib 20250912 [required by ocamlformat-lib] - install csexp 1.5.2 [required by ocamlformat] - install camlp-streams 5.0.1 [required by ocamlformat-lib] - install seq base [required by re] - install menhirSdk 20250912 [required by ocamlformat-lib] - install fix 20250919 [required by ocamlformat-lib] - install menhirCST 20250912 [required by menhir] - install ocamlfind 1.9.8 [required by ocp-indent, astring, fpath, uuseg] - install dune-build-info 3.20.2 [required by ocamlformat-lib] - install cmdliner 2.0.0 [required by ocamlformat] - install ocaml-version 4.0.3 [required by ocamlformat-lib] - install dune-configurator 3.20.2 [required by base] - install re 1.11.0 [required by ocamlformat] - install menhir 20250912 [required by ocamlformat-lib] - install topkg 1.1.0 [required by fpath, astring, uuseg] - install ocp-indent 1.9.0 [required by ocamlformat-lib] - install base v0.14.3 [required by ocamlformat-lib] - install uutf 1.0.4 [required by ocamlformat-lib] - install astring 0.8.5 [required by ocamlformat-lib] - install stdio v0.14.0 [required by ocamlformat-lib] - install uucp 15.0.0 [required by uuseg] - install fpath 0.7.3 [required by ocamlformat-lib] - install uuseg 15.0.0 [required by ocamlformat-lib] - install ocamlformat-lib 0.28.1 [required by ocamlformat] - install ocamlformat 0.28.1 ===== 28 to install ===== <><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><><><> [astring.0.8.5] found in cache [base.v0.14.3] found in cache [camlp-streams.5.0.1] found in cache [cmdliner.2.0.0] found in cache [csexp.1.5.2] found in cache [dune-build-info.3.20.2] found in cache [dune-configurator.3.20.2] found in cache [either.1.0.0] found in cache [fix.20250919] found in cache [fpath.0.7.3] found in cache [menhir.20250912] found in cache [menhirCST.20250912] found in cache [menhirLib.20250912] found in cache [menhirSdk.20250912] found in cache [ocaml-version.4.0.3] found in cache [ocamlbuild.0.16.1] found in cache [ocamlfind.1.9.8] found in cache [ocamlformat.0.28.1] found in cache [ocamlformat-lib.0.28.1] found in cache [ocp-indent.1.9.0] found in cache [re.1.11.0] found in cache [sexplib0.v0.14.0] found in cache [stdio.v0.14.0] found in cache [topkg.1.1.0] found in cache [uucp.15.0.0] found in cache [uuseg.15.0.0] found in cache [uutf.1.0.4] found in cache <><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><> -> installed seq.base -> installed camlp-streams.5.0.1 -> installed csexp.1.5.2 -> installed either.1.0.0 -> installed fix.20250919 -> installed cmdliner.2.0.0 -> installed menhirCST.20250912 -> installed menhirLib.20250912 -> installed menhirSdk.20250912 -> installed ocaml-version.4.0.3 -> installed re.1.11.0 -> installed sexplib0.v0.14.0 -> installed dune-build-info.3.20.2 -> installed dune-configurator.3.20.2 -> installed ocamlfind.1.9.8 -> installed ocp-indent.1.9.0 -> installed ocamlbuild.0.16.1 -> installed base.v0.14.3 -> installed topkg.1.1.0 -> installed stdio.v0.14.0 -> installed uutf.1.0.4 -> installed astring.0.8.5 -> installed menhir.20250912 -> installed fpath.0.7.3 -> installed uucp.15.0.0 -> installed uuseg.15.0.0 -> installed ocamlformat-lib.0.28.1 -> installed ocamlformat.0.28.1 Done. <><> ocp-indent.1.9.0 installed successfully ><><><><><><><><><><><><><><><><><> => This package requires additional configuration for use in editors. Install package 'user-setup', or manually: * for Emacs, add these lines to ~/.emacs: (add-to-list 'load-path "/home/opam/.opam/4.08/share/emacs/site-lisp") (require 'ocp-indent) * for Vim, add this line to ~/.vimrc: set rtp^="/home/opam/.opam/4.08/share/ocp-indent/vim" # Run eval $(opam env) to update the current shell environment 2025-11-13 21:05.07 ---> saved as "1108d0478a8cf00251254042bd4c10cc2aa664b7db87eec561d4d50aaa38cd9f" /src: (copy (src .) (dst /src/)) 2025-11-13 21:05.08 ---> saved as "9c6799e12caff8aa490a18c5aba65b8da92913b9cf32b8e53b9208cd55930900" /src: (run (shell "opam exec -- dune build @fmt --ignore-promoted-rules || (echo \"dune build @fmt failed\"; exit 2)")) File "tensor/ppx_extend_dsls.ml", line 1, characters 0-0: diff --git a/_build/default/tensor/ppx_extend_dsls.ml b/_build/default/tensor/.formatted/ppx_extend_dsls.ml index e30e785..352c5b7 100644 --- a/_build/default/tensor/ppx_extend_dsls.ml +++ b/_build/default/tensor/.formatted/ppx_extend_dsls.ml @@ -50,19 +50,19 @@ let str_expander ~loc:pstr_loc ~path:_ str_items = let item_bindings, op_item_bindings = List.unzip @@ List.concat_map str_items ~f:(function - | { pstr_desc = Pstr_value (Nonrecursive, bindings); pstr_loc = loc; _ } -> - List.map bindings ~f:(fun binding -> - let params, binding = transform_dsl_binding ~loc ~dsl_name binding in - let op_binding = transform_op_binding params binding in - (binding, op_binding)) - | { pstr_loc = loc; _ } -> - let pat = Ast_helper.Pat.var ~loc { txt = "syntax_error"; loc } in - let v = - Ast_builder.Default.pexp_extension ~loc - @@ Location.error_extensionf ~loc - "ppx_extend_dsls: currently only non-recursive value bindings are supported" - in - [ (Ast_helper.Vb.mk ~loc pat v, Ast_helper.Vb.mk ~loc pat v) ]) + | { pstr_desc = Pstr_value (Nonrecursive, bindings); pstr_loc = loc; _ } -> + List.map bindings ~f:(fun binding -> + let params, binding = transform_dsl_binding ~loc ~dsl_name binding in + let op_binding = transform_op_binding params binding in + (binding, op_binding)) + | { pstr_loc = loc; _ } -> + let pat = Ast_helper.Pat.var ~loc { txt = "syntax_error"; loc } in + let v = + Ast_builder.Default.pexp_extension ~loc + @@ Location.error_extensionf ~loc + "ppx_extend_dsls: currently only non-recursive value bindings are supported" + in + [ (Ast_helper.Vb.mk ~loc pat v, Ast_helper.Vb.mk ~loc pat v) ]) in let item = { pstr_desc = Pstr_value (Nonrecursive, item_bindings); pstr_loc } in let op_item = { pstr_desc = Pstr_value (Nonrecursive, op_item_bindings); pstr_loc } in File "tensor/shape.mli", line 1, characters 0-0: diff --git a/_build/default/tensor/shape.mli b/_build/default/tensor/.formatted/shape.mli index 75ff71a..a68d82e 100644 --- a/_build/default/tensor/shape.mli +++ b/_build/default/tensor/.formatted/shape.mli @@ -195,8 +195,8 @@ type logic = [s1], hence the name. *) | Broadcast_tern of ternary_type * t * t * t (** Matches the shapes for a ternary operation. *) | Terminal of { is_param : bool; logic : terminal_type } - (** Extracts any available shape information from the initialization. - The [is_param] field indicates if this is a parameter tensor that requires gradients. *) + (** Extracts any available shape information from the initialization. The [is_param] field + indicates if this is a parameter tensor that requires gradients. *) [@@deriving equal, sexp_of] type update_id [@@deriving equal, compare, hash, sexp] File "test/operations/attention_test.ml", line 1, characters 0-0: diff --git a/_build/default/test/operations/attention_test.ml b/_build/default/test/operations/.formatted/attention_test.ml index cf36028..3a2670a 100644 --- a/_build/default/test/operations/attention_test.ml +++ b/_build/default/test/operations/.formatted/attention_test.ml @@ -19,7 +19,6 @@ let () = in (* Create input tensors *) - let seq = TDSL.range_of_shape ~label:[ "tgt" ] ~batch_dims:[ batch_size; tgt_seq_len ] ~input_dims:[] ~output_dims:[ tgt_vocab_size ] () File "arrayjit/test/tree_map_test.ml", line 1, characters 0-0: diff --git a/_build/default/arrayjit/test/tree_map_test.ml b/_build/default/arrayjit/test/.formatted/tree_map_test.ml index 5f9acfa..3939c56 100644 --- a/_build/default/arrayjit/test/tree_map_test.ml +++ b/_build/default/arrayjit/test/.formatted/tree_map_test.ml @@ -5,7 +5,6 @@ open Utils (* Demo of Tree_map with tree-preserving sexp output *) let () = let open Tree_map in - (* Create a tree by inserting values *) let tree = empty @@ -23,8 +22,10 @@ let () = printf "%s\n\n" (Sexp.to_string_hum (sexp_of_t Int.sexp_of_t String.sexp_of_t tree)); (* Test lookups *) - printf "Finding key 4: %s\n" (Option.value ~default:"not found" (find ~compare:Int.compare ~key:4 tree)); - printf "Finding key 10: %s\n" (Option.value ~default:"not found" (find ~compare:Int.compare ~key:10 tree)); + printf "Finding key 4: %s\n" + (Option.value ~default:"not found" (find ~compare:Int.compare ~key:4 tree)); + printf "Finding key 10: %s\n" + (Option.value ~default:"not found" (find ~compare:Int.compare ~key:10 tree)); (* Print as association list *) printf "\nAs alist (in-order): "; File "arrayjit/lib/context.ml", line 1, characters 0-0: diff --git a/_build/default/arrayjit/lib/context.ml b/_build/default/arrayjit/lib/.formatted/context.ml index 9752637..d1edcba 100644 --- a/_build/default/arrayjit/lib/context.ml +++ b/_build/default/arrayjit/lib/.formatted/context.ml @@ -24,7 +24,7 @@ type backend_wrapper = -> backend_wrapper type t = { - backend_wrapper : (backend_wrapper [@sexp.opaque]); + backend_wrapper : (backend_wrapper[@sexp.opaque]); device_id : int; backend_name : string; initialized_nodes : Set.M(Tn).t; (* Track which nodes have been initialized *) File "test/operations/transformer_test.ml", line 1, characters 0-0: diff --git a/_build/default/test/operations/transformer_test.ml b/_build/default/test/operations/.formatted/transformer_test.ml index 7b2d45f..f561579 100644 --- a/_build/default/test/operations/transformer_test.ml +++ b/_build/default/test/operations/.formatted/transformer_test.ml @@ -33,30 +33,32 @@ let () = (* For teacher forcing: create shifted versions of target sequence *) (* tgt_input: positions 0 to tgt_seq_len-2 (all but last) *) let tgt_input = - TDSL.range_of_shape ~label:[ "tgt_input" ] ~batch_dims:[ batch_size; tgt_seq_len - 1 ] + TDSL.range_of_shape ~label:[ "tgt_input" ] + ~batch_dims:[ batch_size; tgt_seq_len - 1 ] ~input_dims:[] ~output_dims:[ tgt_vocab_size ] () in (* tgt_target: positions 1 to tgt_seq_len-1 (all but first) *) (* In practice, this would be shifted token IDs, here we use one-hot for simplicity *) let tgt_target = - NTDSL.init ~l:"tgt_target" ~prec:Ir.Ops.single ~b:[ batch_size; tgt_seq_len - 1 ] ~i:[] - ~o:[ tgt_vocab_size ] + NTDSL.init ~l:"tgt_target" ~prec:Ir.Ops.single + ~b:[ batch_size; tgt_seq_len - 1 ] + ~i:[] ~o:[ tgt_vocab_size ] ~f:(function | [| _b; s; v |] -> (* Create a simple one-hot pattern for testing *) if v = Int.((s + 1) % tgt_vocab_size) then 1. else 0. - | idcs -> - failwith @@ "Invalid indices: " - ^ Sexp.to_string_hum ([%sexp_of: int array] idcs)) + | idcs -> failwith @@ "Invalid indices: " ^ Sexp.to_string_hum ([%sexp_of: int array] idcs)) () in (* Create a causal mask for the decoder input (shifted target sequence) *) (* Mask should be 0 for positions to mask out, 1 for positions to keep *) let mask = - NTDSL.init ~l:"mask" ~prec:Ir.Ops.single ~b:[ batch_size; tgt_seq_len - 1 ] - ~i:[ tgt_seq_len - 1 ] ~o:[ 1 ] + NTDSL.init ~l:"mask" ~prec:Ir.Ops.single + ~b:[ batch_size; tgt_seq_len - 1 ] + ~i:[ tgt_seq_len - 1 ] + ~o:[ 1 ] ~f:(function | [| _; s; _; t |] -> if s >= t then 1. else 0. | idcs -> @@ -78,7 +80,6 @@ let () = let _ctx = Ocannl.Train.forward_once ~output_cd_file:true ~bindings ctx loss in (* Verify shapes *) - Stdio.printf "Loss shape:\n%s\n" - (Sexp.to_string_hum ([%sexp_of: Shape.t] loss.Tensor.shape)); + Stdio.printf "Loss shape:\n%s\n" (Sexp.to_string_hum ([%sexp_of: Shape.t] loss.Tensor.shape)); Stdio.printf "Logits shape:\n%s\n%!" (Sexp.to_string_hum ([%sexp_of: Shape.t] logits.Tensor.shape)) File "test/operations/test_where_simple.ml", line 1, characters 0-0: diff --git a/_build/default/test/operations/test_where_simple.ml b/_build/default/test/operations/.formatted/test_where_simple.ml index 3a1f08c..9940f2a 100644 --- a/_build/default/test/operations/test_where_simple.ml +++ b/_build/default/test/operations/.formatted/test_where_simple.ml @@ -7,7 +7,7 @@ let () = Tensor.unsafe_reinitialize (); let ctx = Context.auto () in (* Simple test: where(true, x, y) should have gradient flow to x only *) - let x = Tensor.number ~grad_spec:Require_grad 2.0 in + let x = Tensor.number ~grad_spec:Require_grad 2.0 in let y = Tensor.number ~grad_spec:Require_grad 3.0 in let cond = Tensor.number 1.0 in (* true *) File "arrayjit/lib/indexing.ml", line 1, characters 0-0: diff --git a/_build/default/arrayjit/lib/indexing.ml b/_build/default/arrayjit/lib/.formatted/indexing.ml index e4c9e9b..89414e4 100644 --- a/_build/default/arrayjit/lib/indexing.ml +++ b/_build/default/arrayjit/lib/.formatted/indexing.ml @@ -291,15 +291,15 @@ let identity_projections ?debug_info ?derived_for ~lhs_dims () = let reflect_projection ~(dims : int array) ~(projection : axis_index array) = Array.zip_exn dims projection |> Array.fold_right ~init:(1, [], 0) ~f:(fun (dim, idx) (stride, symbols, offset) -> - match idx with - | Fixed_idx fixed_offset -> (stride * dim, symbols, offset + (fixed_offset * stride)) - | Iterator sym -> (stride * dim, (stride, sym) :: symbols, offset) - | Affine { symbols = affine_symbols; offset = affine_offset } -> - let new_symbols = - List.map affine_symbols ~f:(fun (coeff, sym) -> (coeff * stride, sym)) - in - (stride * dim, new_symbols @ symbols, offset + (affine_offset * stride)) - | Sub_axis -> (stride * dim, symbols, offset)) + match idx with + | Fixed_idx fixed_offset -> (stride * dim, symbols, offset + (fixed_offset * stride)) + | Iterator sym -> (stride * dim, (stride, sym) :: symbols, offset) + | Affine { symbols = affine_symbols; offset = affine_offset } -> + let new_symbols = + List.map affine_symbols ~f:(fun (coeff, sym) -> (coeff * stride, sym)) + in + (stride * dim, new_symbols @ symbols, offset + (affine_offset * stride)) + | Sub_axis -> (stride * dim, symbols, offset)) |> fun (_, symbols, offset) -> Affine { symbols; offset } type variable_ref = { ref_label : string; mutable solved_dim : int option } File "arrayjit/lib/datatypes.ml", line 1, characters 0-0: diff --git a/_build/default/arrayjit/lib/datatypes.ml b/_build/default/arrayjit/lib/.formatted/datatypes.ml index 35404a7..d1a76ca 100644 --- a/_build/default/arrayjit/lib/datatypes.ml +++ b/_build/default/arrayjit/lib/.formatted/datatypes.ml @@ -39,8 +39,8 @@ let tl_exn = function | Empty -> raise @@ Not_found_s (Sexp.Atom "mutable_list.tl_exn") | Cons { tl; _ } -> tl -(** A dynamic array of weak references. *) type 'a weak_dynarray = 'a Stdlib.Weak.t ref +(** A dynamic array of weak references. *) let weak_create () : 'a weak_dynarray = ref @@ Stdlib.Weak.create 0 @@ -67,12 +67,12 @@ let weak_iter (arr : 'a weak_dynarray) ~f = Option.iter (W.get !arr i) ~f done -(** A lazy value that can be safely forced and compared by unique ID. *) type 'a safe_lazy = { mutable value : [ `Callback of unit -> 'a | `Value of 'a ]; unique_id : string; } [@@deriving sexp_of] +(** A lazy value that can be safely forced and compared by unique ID. *) let safe_lazy unique_id f = { value = `Callback f; unique_id } @@ -123,37 +123,42 @@ let sexp_of_safe_lazy sexp_of_elem gated = Sexp.List [ Sexp.Atom "value"; status ]; ] -(** A persistent map implemented as a balanced binary tree. - The sexp_of function preserves and displays the tree structure. *) +(** A persistent map implemented as a balanced binary tree. The sexp_of function preserves and + displays the tree structure. *) module Tree_map = struct type ('k, 'v) t = | Empty - | Node of { - key : 'k; - value : 'v; - left : ('k, 'v) t; - right : ('k, 'v) t; - height : int; - } + | Node of { key : 'k; value : 'v; left : ('k, 'v) t; right : ('k, 'v) t; height : int } let empty = Empty - let height = function Empty -> 0 | Node { height; _ } -> height let create key value left right = Node { key; value; left; right; height = 1 + max (height left) (height right) } - let balance_factor = function - | Empty -> 0 - | Node { left; right; _ } -> height left - height right + let balance_factor = function Empty -> 0 | Node { left; right; _ } -> height left - height right let rotate_right = function - | Node { key; value; left = Node { key = lkey; value = lvalue; left = ll; right = lr; _ }; right; _ } -> + | Node + { + key; + value; + left = Node { key = lkey; value = lvalue; left = ll; right = lr; _ }; + right; + _; + } -> create lkey lvalue ll (create key value lr right) | t -> t let rotate_left = function - | Node { key; value; left; right = Node { key = rkey; value = rvalue; left = rl; right = rr; _ }; _ } -> + | Node + { + key; + value; + left; + right = Node { key = rkey; value = rvalue; left = rl; right = rr; _ }; + _; + } -> create rkey rvalue (create key value left rl) rr | t -> t @@ -162,18 +167,22 @@ module Tree_map = struct | bf when bf > 1 -> ( match t with | Node { left; _ } when balance_factor left < 0 -> - rotate_right (create (match t with Node n -> n.key | _ -> assert false) - (match t with Node n -> n.value | _ -> assert false) - (rotate_left left) - (match t with Node n -> n.right | _ -> assert false)) + rotate_right + (create + (match t with Node n -> n.key | _ -> assert false) + (match t with Node n -> n.value | _ -> assert false) + (rotate_left left) + (match t with Node n -> n.right | _ -> assert false)) | _ -> rotate_right t) | bf when bf < -1 -> ( match t with | Node { right; _ } when balance_factor right > 0 -> - rotate_left (create (match t with Node n -> n.key | _ -> assert false) - (match t with Node n -> n.value | _ -> assert false) - (match t with Node n -> n.left | _ -> assert false) - (rotate_right right)) + rotate_left + (create + (match t with Node n -> n.key | _ -> assert false) + (match t with Node n -> n.value | _ -> assert false) + (match t with Node n -> n.left | _ -> assert false) + (rotate_right right)) | _ -> rotate_left t) | _ -> t @@ -200,7 +209,9 @@ module Tree_map = struct | Empty -> false | Node n -> let c = compare key n.key in - if c = 0 then true else if c < 0 then mem ~compare ~key n.left else mem ~compare ~key n.right + if c = 0 then true + else if c < 0 then mem ~compare ~key n.left + else mem ~compare ~key n.right let rec fold t ~init ~f = match t with @@ -221,14 +232,12 @@ module Tree_map = struct let rec map t ~f = match t with | Empty -> Empty - | Node n -> - create n.key (f n.value) (map n.left ~f) (map n.right ~f) + | Node n -> create n.key (f n.value) (map n.left ~f) (map n.right ~f) let rec mapi t ~f = match t with | Empty -> Empty - | Node n -> - create n.key (f ~key:n.key ~data:n.value) (mapi n.left ~f) (mapi n.right ~f) + | Node n -> create n.key (f ~key:n.key ~data:n.value) (mapi n.left ~f) (mapi n.right ~f) let to_alist t = List.rev (fold t ~init:[] ~f:(fun ~key ~data acc -> (key, data) :: acc)) File "test/operations/zero2hero_1of7.ml", line 1, characters 0-0: diff --git a/_build/default/test/operations/zero2hero_1of7.ml b/_build/default/test/operations/.formatted/zero2hero_1of7.ml index f68634c..d2bc5e2 100644 --- a/_build/default/test/operations/zero2hero_1of7.ml +++ b/_build/default/test/operations/.formatted/zero2hero_1of7.ml @@ -175,9 +175,9 @@ let%expect_test "Graph drawing fetch" = let ys, dys = Array.unzip @@ Array.mapi xs ~f:(fun i _ -> - step_ref := i; - Train.run ctx fx_routine; - (fx.@[0], x.@%[0])) + step_ref := i; + Train.run ctx fx_routine; + (fx.@[0], x.@%[0])) in (* It is fine to loop around the data: it's "next epoch". We redo the work though. *) let plot_box = File "test/operations/test_random_histograms.ml", line 1, characters 0-0: diff --git a/_build/default/test/operations/test_random_histograms.ml b/_build/default/test/operations/.formatted/test_random_histograms.ml index 7d0e22d..558b282 100644 --- a/_build/default/test/operations/test_random_histograms.ml +++ b/_build/default/test/operations/.formatted/test_random_histograms.ml @@ -18,16 +18,15 @@ let print_histogram bins ~title ~max_width = let max_count = Array.max_elt bins ~compare:Int.compare |> Option.value ~default:0 in let total = Array.fold bins ~init:0 ~f:( + ) in Array.iteri bins ~f:(fun i count -> - let bar_width = (count * max_width) / max_count in + let bar_width = count * max_width / max_count in let bar = String.make bar_width '#' in - let percentage = (Float.of_int count /. Float.of_int total) *. 100.0 in + let percentage = Float.of_int count /. Float.of_int total *. 100.0 in printf "Bin %2d: %s %4d (%.1f%%)\n" i bar count percentage) let test_uniform_at_histogram () = Tensor.unsafe_reinitialize (); let ctx = Context.auto () in let module O = TDSL.O in - (* Generate a large batch of random numbers using uniform_at *) (* Note: uniform_at produces 4 values per counter input (from uint4x32) *) let num_counters = 2500 in @@ -42,8 +41,8 @@ let test_uniform_at_histogram () = ignore (Ocannl.Train.forward_once ctx uniform_values); let result = Ir.Tnode.get_values uniform_values.value in - printf "Generated %d values from %d counters (%.1fx expansion)\n" - (Array.length result) num_counters + printf "Generated %d values from %d counters (%.1fx expansion)\n" (Array.length result) + num_counters (Float.of_int (Array.length result) /. Float.of_int num_counters); (* Create and print histogram *) @@ -52,10 +51,9 @@ let test_uniform_at_histogram () = print_histogram bins ~title:"Uniform Distribution [0, 1) Histogram" ~max_width:40; (* Statistical tests *) - let mean = Array.fold result ~init:0.0 ~f:(+.) /. Float.of_int (Array.length result) in + let mean = Array.fold result ~init:0.0 ~f:( +. ) /. Float.of_int (Array.length result) in let variance = - Array.fold result ~init:0.0 ~f:(fun acc x -> - acc +. ((x -. mean) *. (x -. mean))) + Array.fold result ~init:0.0 ~f:(fun acc x -> acc +. ((x -. mean) *. (x -. mean))) /. Float.of_int (Array.length result) in let std_dev = Float.sqrt variance in @@ -73,8 +71,8 @@ let test_uniform_at_histogram () = let diff = Float.of_int observed -. expected_per_bin in acc +. (diff *. diff /. expected_per_bin)) in - printf " Chi-square statistic: %.2f (df=%d, critical value at 0.05: ~%.2f)\n" - chi_square (num_bins - 1) 30.14; + printf " Chi-square statistic: %.2f (df=%d, critical value at 0.05: ~%.2f)\n" chi_square + (num_bins - 1) 30.14; (* Check if all values are in range *) let all_in_range = Array.for_all result ~f:(fun x -> Float.(x >= 0.0 && x < 1.0)) in @@ -84,7 +82,6 @@ let test_normal_at_histogram () = Tensor.unsafe_reinitialize (); let ctx = Context.auto () in let module O = TDSL.O in - (* Generate a large batch of random numbers using normal_at *) (* Note: normal_at also produces 4 values per counter input *) let num_counters = 2500 in @@ -100,10 +97,9 @@ let test_normal_at_histogram () = let result = Ir.Tnode.get_values normal_values.value in (* Calculate statistics *) - let mean = Array.fold result ~init:0.0 ~f:(+.) /. Float.of_int (Array.length result) in + let mean = Array.fold result ~init:0.0 ~f:( +. ) /. Float.of_int (Array.length result) in let variance = - Array.fold result ~init:0.0 ~f:(fun acc x -> - acc +. ((x -. mean) *. (x -. mean))) + Array.fold result ~init:0.0 ~f:(fun acc x -> acc +. ((x -. mean) *. (x -. mean))) /. Float.of_int (Array.length result) in let std_dev = Float.sqrt variance in @@ -124,15 +120,9 @@ let test_normal_at_histogram () = printf " Max: %.4f\n" max_val; (* Check what percentage falls within standard deviations *) - let within_1_std = - Array.count result ~f:(fun x -> Float.(abs x <= 1.0)) - in - let within_2_std = - Array.count result ~f:(fun x -> Float.(abs x <= 2.0)) - in - let within_3_std = - Array.count result ~f:(fun x -> Float.(abs x <= 3.0)) - in + let within_1_std = Array.count result ~f:(fun x -> Float.(abs x <= 1.0)) in + let within_2_std = Array.count result ~f:(fun x -> Float.(abs x <= 2.0)) in + let within_3_std = Array.count result ~f:(fun x -> Float.(abs x <= 3.0)) in printf " Within 1 std dev: %.1f%% (expected: ~68.3%%)\n" (Float.of_int within_1_std /. Float.of_int (Array.length result) *. 100.0); @@ -143,20 +133,23 @@ let test_normal_at_histogram () = (* Normality test using skewness and kurtosis *) let skewness = - let sum_cubed = Array.fold result ~init:0.0 ~f:(fun acc x -> - let diff = x -. mean in - acc +. (diff *. diff *. diff)) + let sum_cubed = + Array.fold result ~init:0.0 ~f:(fun acc x -> + let diff = x -. mean in + acc +. (diff *. diff *. diff)) in sum_cubed /. (Float.of_int (Array.length result) *. std_dev *. std_dev *. std_dev) in let kurtosis = - let sum_fourth = Array.fold result ~init:0.0 ~f:(fun acc x -> - let diff = x -. mean in - let diff2 = diff *. diff in - acc +. (diff2 *. diff2)) + let sum_fourth = + Array.fold result ~init:0.0 ~f:(fun acc x -> + let diff = x -. mean in + let diff2 = diff *. diff in + acc +. (diff2 *. diff2)) in - (sum_fourth /. (Float.of_int (Array.length result) *. std_dev *. std_dev *. std_dev *. std_dev)) -. 3.0 + (sum_fourth /. (Float.of_int (Array.length result) *. std_dev *. std_dev *. std_dev *. std_dev)) + -. 3.0 in printf " Skewness: %.4f (expected: ~0.0)\n" skewness; @@ -166,7 +159,6 @@ let test_batched_generation_consistency () = Tensor.unsafe_reinitialize (); let ctx = Context.auto () in let module O = TDSL.O in - (* Test that batched generation gives consistent results *) let batch_size = 100 in let num_batches = 10 in @@ -205,9 +197,8 @@ let test_batched_generation_consistency () = Array.sort sorted ~compare:Float.compare; let unique = ref 1 in for i = 1 to Array.length sorted - 1 do - let diff = Float.abs (sorted.(i) -. sorted.(i-1)) in - if Float.(diff > 1e-7) then - unique := !unique + 1 + let diff = Float.abs (sorted.(i) -. sorted.(i - 1)) in + if Float.(diff > 1e-7) then unique := !unique + 1 done; !unique in @@ -217,11 +208,9 @@ let test_batched_generation_consistency () = let unique_normal = count_unique !all_normal_values in printf "Generated %d values in %d batches of %d\n" total_values num_batches batch_size; - printf "Uniform values: %d unique out of %d (%.1f%%)\n" - unique_uniform total_values + printf "Uniform values: %d unique out of %d (%.1f%%)\n" unique_uniform total_values (Float.of_int unique_uniform /. Float.of_int total_values *. 100.0); - printf "Normal values: %d unique out of %d (%.1f%%)\n" - unique_normal total_values + printf "Normal values: %d unique out of %d (%.1f%%)\n" unique_normal total_values (Float.of_int unique_normal /. Float.of_int total_values *. 100.0); (* Verify batch consistency of statistical properties *) @@ -234,40 +223,44 @@ let test_batched_generation_consistency () = let normal_batch = Array.sub !all_normal_values ~pos:start_idx ~len:batch_size in batch_means_uniform.(batch) <- - Array.fold uniform_batch ~init:0.0 ~f:(+.) /. Float.of_int batch_size; + Array.fold uniform_batch ~init:0.0 ~f:( +. ) /. Float.of_int batch_size; batch_means_normal.(batch) <- - Array.fold normal_batch ~init:0.0 ~f:(+.) /. Float.of_int batch_size + Array.fold normal_batch ~init:0.0 ~f:( +. ) /. Float.of_int batch_size done; let mean_of_means_uniform = - Array.fold batch_means_uniform ~init:0.0 ~f:(+.) /. Float.of_int num_batches + Array.fold batch_means_uniform ~init:0.0 ~f:( +. ) /. Float.of_int num_batches in let mean_of_means_normal = - Array.fold batch_means_normal ~init:0.0 ~f:(+.) /. Float.of_int num_batches + Array.fold batch_means_normal ~init:0.0 ~f:( +. ) /. Float.of_int num_batches in let std_of_means_uniform = - let diff_sum = Array.fold batch_means_uniform ~init:0.0 ~f:(fun acc x -> - let diff = x -. mean_of_means_uniform in - acc +. (diff *. diff)) in + let diff_sum = + Array.fold batch_means_uniform ~init:0.0 ~f:(fun acc x -> + let diff = x -. mean_of_means_uniform in + acc +. (diff *. diff)) + in Float.sqrt (diff_sum /. Float.of_int num_batches) in let std_of_means_normal = - let diff_sum = Array.fold batch_means_normal ~init:0.0 ~f:(fun acc x -> - let diff = x -. mean_of_means_normal in - acc +. (diff *. diff)) in + let diff_sum = + Array.fold batch_means_normal ~init:0.0 ~f:(fun acc x -> + let diff = x -. mean_of_means_normal in + acc +. (diff *. diff)) + in Float.sqrt (diff_sum /. Float.of_int num_batches) in printf "\nBatch means consistency:\n"; - printf " Uniform: mean of batch means = %.4f, std = %.4f\n" - mean_of_means_uniform std_of_means_uniform; - printf " Normal: mean of batch means = %.4f, std = %.4f\n" - mean_of_means_normal std_of_means_normal + printf " Uniform: mean of batch means = %.4f, std = %.4f\n" mean_of_means_uniform + std_of_means_uniform; + printf " Normal: mean of batch means = %.4f, std = %.4f\n" mean_of_means_normal + std_of_means_normal let () = test_uniform_at_histogram (); printf "\n"; test_normal_at_histogram (); printf "\n"; - test_batched_generation_consistency () \ No newline at end of file + test_batched_generation_consistency () File "test/operations/primitive_ops.ml", line 1, characters 0-0: diff --git a/_build/default/test/operations/primitive_ops.ml b/_build/default/test/operations/.formatted/primitive_ops.ml index ccf0ebb..e3b3174 100644 --- a/_build/default/test/operations/primitive_ops.ml +++ b/_build/default/test/operations/.formatted/primitive_ops.ml @@ -31,9 +31,9 @@ let plot_unop ?(x_min = -5.) ?(x_max = 5.) ~f () = let ys, dys = Array.unzip @@ Array.mapi xs ~f:(fun i _ -> - step_ref := i; - Train.run ctx fx_routine; - (fx.@[0], x.@%[0])) + step_ref := i; + Train.run ctx fx_routine; + (fx.@[0], x.@%[0])) in (* It is fine to loop around the data: it's "next epoch". We redo the work though. *) PrintBox_utils.plot ~x_label:"x" ~y_label:"f(x)" File "tensor/ppx_shared.ml", line 1, characters 0-0: diff --git a/_build/default/tensor/ppx_shared.ml b/_build/default/tensor/.formatted/ppx_shared.ml index 8c26a58..33ae188 100644 --- a/_build/default/tensor/ppx_shared.ml +++ b/_build/default/tensor/.formatted/ppx_shared.ml @@ -298,8 +298,8 @@ let expr_expander_with_punning translate ~loc ~path:_ payload = let vbss, bindings = List.unzip @@ List.map bindings ~f:(fun vb -> - let vbs, v = translate ?ident_label:(Some vb.pvb_pat) vb.pvb_expr in - (vbs, { vb with pvb_expr = v })) + let vbs, v = translate ?ident_label:(Some vb.pvb_pat) vb.pvb_expr in + (vbs, { vb with pvb_expr = v })) in let expr = { payload with pexp_desc = Pexp_let (recflag, bindings, body) } in let_opt ~loc (reduce_vbss vbss) expr File "tensor/ppx_op.ml", line 1, characters 0-0: diff --git a/_build/default/tensor/ppx_op.ml b/_build/default/tensor/.formatted/ppx_op.ml index 2873eda..df32d9c 100644 --- a/_build/default/tensor/ppx_op.ml +++ b/_build/default/tensor/.formatted/ppx_op.ml @@ -367,14 +367,14 @@ let rec translate ~no_grads_for_inline_defs ~num_configs ~is_toplevel ~opt_label let vbs_args, processed_args = List.unzip @@ List.mapi args ~f:(fun i (arg_label, arg_expr) -> - match unit_position with - | Some unit_pos when i < unit_pos -> - (* Before unit: preserve as OCaml expression *) - (no_vbs, (arg_label, arg_expr)) - | _ -> - (* After unit or no unit: transform *) - let vbs, e = loop arg_expr in - (vbs, (arg_label, e))) + match unit_position with + | Some unit_pos when i < unit_pos -> + (* Before unit: preserve as OCaml expression *) + (no_vbs, (arg_label, arg_expr)) + | _ -> + (* After unit or no unit: transform *) + let vbs, e = loop arg_expr in + (vbs, (arg_label, e))) in let all_vbs = reduce_vbss (vbs_fn :: vbs_args) in (all_vbs, Ast_builder.Default.pexp_apply ~loc e_fn processed_args) @@ -422,10 +422,10 @@ let rec translate ~no_grads_for_inline_defs ~num_configs ~is_toplevel ~opt_label let labels = Option.to_list label @ List.filter_map args ~f:(function - | { pparam_desc = Pparam_val (_, _, pat); _ } -> - let loc = pat.ppat_loc in - Some [%expr [%e pat2expr pat].Tensor.value.Ir.Tnode.label] - | _ -> None) + | { pparam_desc = Pparam_val (_, _, pat); _ } -> + let loc = pat.ppat_loc in + Some [%expr [%e pat2expr pat].Tensor.value.Ir.Tnode.label] + | _ -> None) in let label_locs = List.map labels ~f:(fun label -> label.pexp_loc) in let label_starts = List.map label_locs ~f:(fun l -> l.loc_start) in @@ -453,8 +453,8 @@ let rec translate ~no_grads_for_inline_defs ~num_configs ~is_toplevel ~opt_label let vbs, cases = List.unzip @@ List.map cases ~f:(fun ({ pc_rhs; _ } as c) -> - let vbs, pc_rhs = loop ~label pc_rhs in - (vbs, { c with pc_rhs })) + let vbs, pc_rhs = loop ~label pc_rhs in + (vbs, { c with pc_rhs })) in ( List.fold vbs ~init:(Map.empty (module String)) @@ -472,8 +472,8 @@ let rec translate ~no_grads_for_inline_defs ~num_configs ~is_toplevel ~opt_label let vbs, cases = List.unzip @@ List.map cases ~f:(fun ({ pc_rhs; _ } as c) -> - let vbs, pc_rhs = loop ?label pc_rhs in - (vbs, { c with pc_rhs })) + let vbs, pc_rhs = loop ?label pc_rhs in + (vbs, { c with pc_rhs })) in ( List.fold vbs ~init:(Map.empty (module String)) @@ -531,18 +531,18 @@ let rec translate ~no_grads_for_inline_defs ~num_configs ~is_toplevel ~opt_label let vbss, cases = List.unzip @@ List.map cases ~f:(fun ({ pc_rhs; _ } as c) -> - let vbs, pc_rhs = loop ?label pc_rhs in - (vbs, { c with pc_rhs })) + let vbs, pc_rhs = loop ?label pc_rhs in + (vbs, { c with pc_rhs })) in (reduce_vbss vbss, { expr with pexp_desc = Pexp_match (expr1, cases) }) | { pexp_desc = Pexp_let (recflag, bindings, body); _ } -> let vbss1, bindings = List.unzip @@ List.map bindings ~f:(fun binding -> - let vbs, pvb_expr = - loop ~label:[%expr [ [%e pat2string binding.pvb_pat] ]] binding.pvb_expr - in - (vbs, { binding with pvb_expr })) + let vbs, pvb_expr = + loop ~label:[%expr [ [%e pat2string binding.pvb_pat] ]] binding.pvb_expr + in + (vbs, { binding with pvb_expr })) in let vbs2, body = loop ?label body in (reduce_vbss (vbss1 @ [ vbs2 ]), { expr with pexp_desc = Pexp_let (recflag, bindings, body) }) File "arrayjit/lib/tnode.ml", line 1, characters 0-0: diff --git a/_build/default/arrayjit/lib/tnode.ml b/_build/default/arrayjit/lib/.formatted/tnode.ml index 9061870..fdce12a 100644 --- a/_build/default/arrayjit/lib/tnode.ml +++ b/_build/default/arrayjit/lib/.formatted/tnode.ml @@ -165,22 +165,22 @@ let debug_memory_mode = function | None -> "unknown" | Some (mem, prov) -> (match mem with - | Effectively_constant -> "Const" - | Virtual -> "Virt" - | Never_virtual -> "Non-virt" - | Local -> "Local" - | Device_only -> "Dev" - | Materialized -> "Material" - | On_device Unset -> "On-dev" - | On_device Shared_cross_streams -> "Dev-shared" - | On_device Per_stream -> "Dev-stream" - | Hosted Constant -> "Host-const" - | Hosted Nonconstant -> "Host-non-const" - | Hosted Unset_hosted -> "Host-unset" - | Hosted Volatile -> "Hosted" - | Hosted (Changed_on_devices Unset) -> "Host&dev" - | Hosted (Changed_on_devices Per_stream) -> "Host&stream" - | Hosted (Changed_on_devices Shared_cross_streams) -> "Host&shared") + | Effectively_constant -> "Const" + | Virtual -> "Virt" + | Never_virtual -> "Non-virt" + | Local -> "Local" + | Device_only -> "Dev" + | Materialized -> "Material" + | On_device Unset -> "On-dev" + | On_device Shared_cross_streams -> "Dev-shared" + | On_device Per_stream -> "Dev-stream" + | Hosted Constant -> "Host-const" + | Hosted Nonconstant -> "Host-non-const" + | Hosted Unset_hosted -> "Host-unset" + | Hosted Volatile -> "Hosted" + | Hosted (Changed_on_devices Unset) -> "Host&dev" + | Hosted (Changed_on_devices Per_stream) -> "Host&stream" + | Hosted (Changed_on_devices Shared_cross_streams) -> "Host&shared") ^ "/" ^ Int.to_string prov let log_debug_info ~from_log_level tn = File "arrayjit/lib/backends.ml", line 1, characters 0-0: diff --git a/_build/default/arrayjit/lib/backends.ml b/_build/default/arrayjit/lib/.formatted/backends.ml index 166603a..b013e06 100644 --- a/_build/default/arrayjit/lib/backends.ml +++ b/_build/default/arrayjit/lib/.formatted/backends.ml @@ -32,7 +32,7 @@ module Add_buffer_retrieval_and_syncing (Backend : No_buffer_retrieval_or_syncin (Fn.compose (List.filter ~f:(fun (_, e) -> not (Backend.is_done e))) @@ Option.value ~default:[]) |> List.iter ~f:(fun (work_stream, e) -> - if not (equal_stream work_stream s) then Backend.will_wait_for ctx e) + if not (equal_stream work_stream s) then Backend.will_wait_for ctx e) let wait_for_ready ~dst ~src tn = let s = src.stream in @@ -40,7 +40,7 @@ module Add_buffer_retrieval_and_syncing (Backend : No_buffer_retrieval_or_syncin (* TODO: maybe it's worthwhile to clean up s.updating_for every now and then. *) Hashtbl.find s.updating_for tn |> Option.iter ~f:(fun upd_e -> - if not (equal_stream s d || Backend.is_done upd_e) then Backend.will_wait_for dst upd_e) + if not (equal_stream s d || Backend.is_done upd_e) then Backend.will_wait_for dst upd_e) let%track3_sexp to_host (ctx : Backend.context) (tn : Tn.t) = match (tn, Map.find ctx.ctx_arrays tn) with @@ -269,13 +269,13 @@ let lower_batch_assignments optim_ctx ?names ?occupancy bindings asgns_l = let occupancy = Option.value occupancy ~default:(fun ~name:_ ~src_n:_ -> true) in Array.unzip @@ Array.mapi names ~f:(fun src_n name -> - let asgns = asgns_l.(src_n) in - if occupancy ~name ~src_n then - ( Some name, - Some - (Assignments.lower optim_ctx ~unoptim_ll_source ~ll_source ~cd_source ~name bound - asgns) ) - else (None, None)) + let asgns = asgns_l.(src_n) in + if occupancy ~name ~src_n then + ( Some name, + Some + (Assignments.lower optim_ctx ~unoptim_ll_source ~ll_source ~cd_source ~name bound asgns) + ) + else (None, None)) let%debug3_sexp verify_prior_context ~use_host_memory ~ctx_arrays ~from_prior_context : unit = Set.iter from_prior_context ~f:(fun tn -> @@ -659,8 +659,7 @@ let%track5_sexp fresh_backend ?backend_name ?(config = For_parallel_copying) () : Backend) | "sync_cc" -> (module Make_device_backend_from_lowered (Schedulers.Sync) (Cc_backend) (Config) : Backend) - | "cuda" -> - (module Raise_backend ((Cuda_backend_impl.Fresh (Config) : Lowered_backend)) : Backend) + | "cuda" -> (module Raise_backend (Cuda_backend_impl.Fresh (Config) : Lowered_backend) : Backend) | "metal" -> - (module Raise_backend ((Metal_backend_impl.Fresh (Config) : Lowered_backend)) : Backend) + (module Raise_backend (Metal_backend_impl.Fresh (Config) : Lowered_backend) : Backend) | backend -> invalid_arg [%string "Backends.fresh_backend: unknown backend %{backend}"] File "arrayjit/lib/ndarray.ml", line 1, characters 0-0: diff --git a/_build/default/arrayjit/lib/ndarray.ml b/_build/default/arrayjit/lib/.formatted/ndarray.ml index efff2f6..ac068a2 100644 --- a/_build/default/arrayjit/lib/ndarray.ml +++ b/_build/default/arrayjit/lib/.formatted/ndarray.ml @@ -691,22 +691,21 @@ let render_array ?(brief = false) ?(prefix = "") ?(entries_per_axis = 4) ?(label let outer_grid v = (if brief then Fn.id else B.frame ~stretch:false) @@ B.init_grid ~bars:true ~line:nlines ~col:ncols (fun ~line ~col -> - if (not brief) && line = 0 && col = 0 then - B.lines @@ List.filter ~f:(Fn.non String.is_empty) @@ [ tag ~pos:v label0 ind0 ] - else if (not brief) && line = 0 then - B.lines - @@ List.filter ~f:(Fn.non String.is_empty) - @@ [ tag ~pos:(col - 1) label2 ind2; tag label4 ind4 ] - else if (not brief) && col = 0 then - B.lines - @@ List.filter ~f:(Fn.non String.is_empty) - @@ [ tag ~pos:(line - 1) label1 ind1; tag label3 ind3 ] - else - let nline = if brief then line else line - 1 in - let ncol = if brief then col else col - 1 in - if elide_for ncol ~ind:ind2 || elide_for nline ~ind:ind1 then - B.hpad 1 @@ B.line "..." - else inner_grid v nline ncol) + if (not brief) && line = 0 && col = 0 then + B.lines @@ List.filter ~f:(Fn.non String.is_empty) @@ [ tag ~pos:v label0 ind0 ] + else if (not brief) && line = 0 then + B.lines + @@ List.filter ~f:(Fn.non String.is_empty) + @@ [ tag ~pos:(col - 1) label2 ind2; tag label4 ind4 ] + else if (not brief) && col = 0 then + B.lines + @@ List.filter ~f:(Fn.non String.is_empty) + @@ [ tag ~pos:(line - 1) label1 ind1; tag label3 ind3 ] + else + let nline = if brief then line else line - 1 in + let ncol = if brief then col else col - 1 in + if elide_for ncol ~ind:ind2 || elide_for nline ~ind:ind1 then B.hpad 1 @@ B.line "..." + else inner_grid v nline ncol) in let screens = B.init_grid ~bars:true ~line:size0 ~col:1 (fun ~line ~col:_ -> File "tensor/tensor.ml", line 1, characters 0-0: diff --git a/_build/default/tensor/tensor.ml b/_build/default/tensor/.formatted/tensor.ml index f8e5c36..6b00695 100644 --- a/_build/default/tensor/tensor.ml +++ b/_build/default/tensor/.formatted/tensor.ml @@ -119,9 +119,9 @@ let%debug7_sexp rec init_params ?skip (t : t) : Asgns.comp = let params : t list = Set.to_list t.params |> (match skip with - | None -> Fn.id - | Some skip -> List.filter ~f:(fun p -> not (Map.mem skip p.value))) - (* Compare to ordered_ts in op -- we need to sort to avoid computed-after-use bugs! *) + | None -> Fn.id + | Some skip -> List.filter ~f:(fun p -> not (Map.mem skip p.value))) + (* Compare to ordered_ts in op -- we need to sort to avoid computed-after-use bugs! *) |> List.sort ~compare:(fun p1 p2 -> Int.ascending p1.id p2.id) in let asgns = File "arrayjit/lib/c_syntax.ml", line 1, characters 0-0: diff --git a/_build/default/arrayjit/lib/c_syntax.ml b/_build/default/arrayjit/lib/.formatted/c_syntax.ml index 566b7f4..d6a4515 100644 --- a/_build/default/arrayjit/lib/c_syntax.ml +++ b/_build/default/arrayjit/lib/.formatted/c_syntax.ml @@ -758,19 +758,19 @@ module C_syntax (B : C_syntax_config) = struct let params : (string * param_source) list = List.rev @@ Hashtbl.fold traced_store ~init:[] ~f:(fun ~key:tn ~data:_ params -> - let backend_info, is_param = - if Tn.is_virtual_force tn 334 then ("Virt", false) - else if in_ctx tn then ("Ctx", true) - else if Tn.is_materialized_force tn 335 then ("Global", true) - else if Tn.known_not_materialized tn then ("Local", false) - else assert false - in - let backend_info = Sexp.Atom backend_info in - if not @@ Utils.sexp_mem ~elem:backend_info tn.backend_info then - tn.backend_info <- Utils.sexp_append ~elem:backend_info tn.backend_info; - if is_param then - (B.typ_of_prec (Lazy.force tn.Tn.prec) ^ " *" ^ get_ident tn, Param_ptr tn) :: params - else params) + let backend_info, is_param = + if Tn.is_virtual_force tn 334 then ("Virt", false) + else if in_ctx tn then ("Ctx", true) + else if Tn.is_materialized_force tn 335 then ("Global", true) + else if Tn.known_not_materialized tn then ("Local", false) + else assert false + in + let backend_info = Sexp.Atom backend_info in + if not @@ Utils.sexp_mem ~elem:backend_info tn.backend_info then + tn.backend_info <- Utils.sexp_append ~elem:backend_info tn.backend_info; + if is_param then + (B.typ_of_prec (Lazy.force tn.Tn.prec) ^ " *" ^ get_ident tn, Param_ptr tn) :: params + else params) in let idx_params = List.map idx_params ~f:(fun s -> @@ -787,7 +787,7 @@ module C_syntax (B : C_syntax_config) = struct Option.( to_list @@ map merge_node ~f:(fun tn -> - ("const " ^ B.typ_of_prec (Lazy.force tn.prec) ^ " *merge_buffer", Merge_buffer))) + ("const " ^ B.typ_of_prec (Lazy.force tn.prec) ^ " *merge_buffer", Merge_buffer))) in let all_params = log_file_param @ merge_param @ idx_params @ params in let sorted_params = File "arrayjit/lib/utils.ml", line 1, characters 0-0: diff --git a/_build/default/arrayjit/lib/utils.ml b/_build/default/arrayjit/lib/.formatted/utils.ml index a170906..d2a97b7 100644 --- a/_build/default/arrayjit/lib/utils.ml +++ b/_build/default/arrayjit/lib/.formatted/utils.ml @@ -119,25 +119,25 @@ let config_file_args = let result = config_lines |> List.filter ~f:(fun l -> - not (String.is_prefix ~prefix:"~~" l || String.is_prefix ~prefix:"#" l)) + not (String.is_prefix ~prefix:"~~" l || String.is_prefix ~prefix:"#" l)) |> List.map ~f:(String.split ~on:'=') |> List.filter_map ~f:(function - | [] -> None - | [ s ] when String.is_empty s -> None - | key :: [ v ] -> - let key = - String.( - lowercase @@ strip ~drop:(fun c -> equal_char '-' c || equal_char ' ' c) key) - in - let key = - if String.is_prefix key ~prefix:"ocannl" then - String.drop_prefix key 6 |> String.strip ~drop:(equal_char '_') - else key - in - str_nonempty ~f:(pair key) v - | l -> - failwith @@ "OCANNL: invalid syntax in the config file " ^ fname - ^ ", should have a single '=' on each non-empty line, found: " ^ String.concat l) + | [] -> None + | [ s ] when String.is_empty s -> None + | key :: [ v ] -> + let key = + String.( + lowercase @@ strip ~drop:(fun c -> equal_char '-' c || equal_char ' ' c) key) + in + let key = + if String.is_prefix key ~prefix:"ocannl" then + String.drop_prefix key 6 |> String.strip ~drop:(equal_char '_') + else key + in + str_nonempty ~f:(pair key) v + | l -> + failwith @@ "OCANNL: invalid syntax in the config file " ^ fname + ^ ", should have a single '=' on each non-empty line, found: " ^ String.concat l) |> Hashtbl.of_alist (module String) |> function | `Ok h -> h @@ -379,11 +379,11 @@ let get_local_debug_runtime = else String.split pairs_str ~on:';' |> List.filter_map ~f:(fun pair_str -> - match String.split pair_str ~on:',' with - | [ id1; id2 ] -> - Option.try_with (fun () -> - (Int.of_string (String.strip id1), Int.of_string (String.strip id2))) - | _ -> None) + match String.split pair_str ~on:',' with + | [ id1; id2 ] -> + Option.try_with (fun () -> + (Int.of_string (String.strip id1), Int.of_string (String.strip id2))) + | _ -> None) in let truncate_children = let arg = get_global_arg ~default:"" ~arg_name:"debug_log_truncate_children" in File "arrayjit/lib/cuda_backend.ml", line 1, characters 0-0: diff --git a/_build/default/arrayjit/lib/cuda_backend.ml b/_build/default/arrayjit/lib/.formatted/cuda_backend.ml index 58be075..4a4fc2a 100644 --- a/_build/default/arrayjit/lib/cuda_backend.ml +++ b/_build/default/arrayjit/lib/.formatted/cuda_backend.ml @@ -935,10 +935,10 @@ end) : Ir.Backend_impl.Lowered_backend = struct Array.mapi code_batch.params_and_names ~f:(fun i pns -> Option.value ~default:None @@ Option.map2 pns ctx_arrays.(i) ~f:(fun (params, name) ctx_arrays -> - let task = - link_proc ~prior_context ~name ~params ~ctx_arrays lowered_bindings run_module - in - Some task)) + let task = + link_proc ~prior_context ~name ~params ~ctx_arrays lowered_bindings run_module + in + Some task)) in (lowered_bindings, procs) Warning: Invalid documentation comment: File "tensor/shape.ml", line 24, characters 0-0: End of text is not allowed in '[...]' (code). File "tensor/shape.ml", line 1, characters 0-0: diff --git a/_build/default/tensor/shape.ml b/_build/default/tensor/.formatted/shape.ml index 79792b5..35864b8 100644 --- a/_build/default/tensor/shape.ml +++ b/_build/default/tensor/.formatted/shape.ml @@ -328,7 +328,7 @@ let axis_map_to_dims_bio (type a) ?(default : a option) (idcs : a axis_map) = let back_axes, front_axes = Map.to_alist axes |> List.partition_map ~f:(fun ({ AxisKey.from_end; pos = i; _ }, v) -> - if from_end then Either.First (i, v) else Second (i, v)) + if from_end then Either.First (i, v) else Second (i, v)) in let back_size = List.fold back_axes ~init:0 ~f:(fun accu (i, _) -> max i accu) in let front_size = List.fold front_axes ~init:0 ~f:(fun accu (i, _) -> max i accu) in @@ -888,21 +888,21 @@ let%debug4_sexp get_inequalities ({ shape = cur_sh; logic; id = _ } as _upd : up ( proj_axis_env, (Option.to_list static_range |> List.map ~f:(fun range -> - Dim_eq - { - d1 = get_dim ~d:range (); - d2 = slice_var; - origin = - [ - { - lhs_name = sh.debug_name; - lhs_kind = `Batch; - rhs_name = Idx.symbol_ident static_symbol; - rhs_kind = `Batch; - operation = Some "Slice"; - }; - ]; - })) + Dim_eq + { + d1 = get_dim ~d:range (); + d2 = slice_var; + origin = + [ + { + lhs_name = sh.debug_name; + lhs_kind = `Batch; + rhs_name = Idx.symbol_ident static_symbol; + rhs_kind = `Batch; + operation = Some "Slice"; + }; + ]; + })) @ [ Row_eq { r1 = expanded_batch; r2 = sh.batch; origin = get_origin `Batch }; Row_eq { r1 = cur_sh.input; r2 = sh.input; origin = get_origin `Input }; @@ -1987,15 +1987,12 @@ let to_string_hum ?(style = Row.Axis_size) (sh : t) = let dims = (row_of_kind kind sh).dims in String.concat ~sep:"," @@ List.mapi dims ~f:(fun i d -> - let num = - match kind with - | `Input -> n_batch + n_outputs + i - | `Output -> n_batch + i - | `Batch -> i - in - match style with - | Row.Only_labels | Axis_size | Projection_and_size -> Row.dim_to_string style d - | Axis_number_and_size -> Int.to_string num ^ ":" ^ Row.dim_to_string style d) + let num = + match kind with `Input -> n_batch + n_outputs + i | `Output -> n_batch + i | `Batch -> i + in + match style with + | Row.Only_labels | Axis_size | Projection_and_size -> Row.dim_to_string style d + | Axis_number_and_size -> Int.to_string num ^ ":" ^ Row.dim_to_string style d) in let batch_dims = dims_to_string `Batch in let input_dims = dims_to_string `Input in File "tensor/ppx_cd.ml", line 1, characters 0-0: diff --git a/_build/default/tensor/ppx_cd.ml b/_build/default/tensor/.formatted/ppx_cd.ml index 21a2fb9..f27b24a 100644 --- a/_build/default/tensor/ppx_cd.ml +++ b/_build/default/tensor/.formatted/ppx_cd.ml @@ -421,8 +421,8 @@ let handle_cases ~bad_pun_hints ~proj_in_scope transl cases = let fields, transformed_cases = List.unzip @@ List.map cases ~f:(fun ({ pc_rhs; _ } as c) -> - let res = transl ~bad_pun_hints ~proj_in_scope pc_rhs in - ((res.vbs, res.typ, res.slot), { c with pc_rhs = res.expr })) + let res = transl ~bad_pun_hints ~proj_in_scope pc_rhs in + ((res.vbs, res.typ, res.slot), { c with pc_rhs = res.expr })) in let vbss, typs, slots = List.unzip3 fields in (* TODO: make the inference of typ and slot more strict by detecting mismatches. *) @@ -450,55 +450,55 @@ let translate ?ident_label (expr : expression) : result = let assignment_op accu_op = loc |> Option.value_or_thunk (Hashtbl.find assignment_ops accu_op) ~default:(fun () _loc -> - ( false, - Ast_builder.Default.pexp_extension ~loc - @@ Location.error_extensionf ~loc - "ppx_ocannl %%cd: expected an assignment operator, one of: %s %s" - "=+ (Add), =- (Sub), =* (Mul),=/ (Div), =** (ToPowOf), =?/ (Relu_gate), =?^ \ - (Satur01_gate), =|| (Or), =&& (And), =@^ (Max), =@- (Min), =^^^^ \ - (threefry4x32), =: (Arg2), =:+, =:-," - " =:*, =:/, =:**, =:?/, =:?^, =:||, =:&&, =:@^, =:@-, =:^^^^ (same with \ - initializing the tensor to the neutral value before the start of the \ - calculation)" )) + ( false, + Ast_builder.Default.pexp_extension ~loc + @@ Location.error_extensionf ~loc + "ppx_ocannl %%cd: expected an assignment operator, one of: %s %s" + "=+ (Add), =- (Sub), =* (Mul),=/ (Div), =** (ToPowOf), =?/ (Relu_gate), =?^ \ + (Satur01_gate), =|| (Or), =&& (And), =@^ (Max), =@- (Min), =^^^^ \ + (threefry4x32), =: (Arg2), =:+, =:-," + " =:*, =:/, =:**, =:?/, =:?^, =:||, =:&&, =:@^, =:@-, =:^^^^ (same with \ + initializing the tensor to the neutral value before the start of the \ + calculation)" )) in let unary_op un_op = loc |> Option.value_or_thunk (Hashtbl.find unary_ops un_op) ~default:(fun () loc -> - ( [%expr Shape.Pointwise_un], - Ast_builder.Default.pexp_extension ~loc - @@ Location.error_extensionf ~loc - "ppx_ocannl %%cd: expected a unary operator, one of: %s" - "id, relu, sat01, exp, log, exp2, log2, sin, cos, sqrt, recip, recip_sqrt, \ - neg, tanh, uint4x32_to_prec_uniform1" )) + ( [%expr Shape.Pointwise_un], + Ast_builder.Default.pexp_extension ~loc + @@ Location.error_extensionf ~loc + "ppx_ocannl %%cd: expected a unary operator, one of: %s" + "id, relu, sat01, exp, log, exp2, log2, sin, cos, sqrt, recip, recip_sqrt, neg, \ + tanh, uint4x32_to_prec_uniform1" )) in let vec_unary_op vec_un_op = loc |> Option.value_or_thunk (Hashtbl.find vec_unary_ops vec_un_op) ~default:(fun () loc -> - ( [%expr Shape.Uint4x32_to_prec_uniform], - Ast_builder.Default.pexp_extension ~loc - @@ Location.error_extensionf ~loc - "ppx_ocannl %%cd: expected a vector unary operator, one of: \ - uint4x32_to_prec_uniform; found: %s" - vec_un_op )) + ( [%expr Shape.Uint4x32_to_prec_uniform], + Ast_builder.Default.pexp_extension ~loc + @@ Location.error_extensionf ~loc + "ppx_ocannl %%cd: expected a vector unary operator, one of: \ + uint4x32_to_prec_uniform; found: %s" + vec_un_op )) in let binary_op bin_op = loc |> Option.value_or_thunk (Hashtbl.find binary_ops bin_op) ~default:(fun () _loc -> - ( [%expr Shape.Pointwise_bin], - Ast_builder.Default.pexp_extension ~loc - @@ Location.error_extensionf ~loc - "ppx_ocannl %%cd: expected a binary operator, one of: %s" - "+ (Add), - (Sub), * (Mul), / (Div), **(ToPowOf), -?/ (Relu_gate), -?^ \ - (Satur01_gate), -/> (Arg2), < (Cmplt), = (Cmpeq), <> (Cmpne), || (Or), && \ - (And), % (Mod), @^(Max), @- (Min), ^^^^ (threefry4x32)" )) + ( [%expr Shape.Pointwise_bin], + Ast_builder.Default.pexp_extension ~loc + @@ Location.error_extensionf ~loc + "ppx_ocannl %%cd: expected a binary operator, one of: %s" + "+ (Add), - (Sub), * (Mul), / (Div), **(ToPowOf), -?/ (Relu_gate), -?^ \ + (Satur01_gate), -/> (Arg2), < (Cmplt), = (Cmpeq), <> (Cmpne), || (Or), && \ + (And), % (Mod), @^(Max), @- (Min), ^^^^ (threefry4x32)" )) in let ternary_op tern_op = loc |> Option.value_or_thunk (Hashtbl.find ternary_ops tern_op) ~default:(fun () _loc -> - ( [%expr Shape.Pointwise_tern], - Ast_builder.Default.pexp_extension ~loc - @@ Location.error_extensionf ~loc - "ppx_ocannl %%cd: expected a ternary operator, one of: where, fma" )) + ( [%expr Shape.Pointwise_tern], + Ast_builder.Default.pexp_extension ~loc + @@ Location.error_extensionf ~loc + "ppx_ocannl %%cd: expected a ternary operator, one of: where, fma" )) in (* TODO: collapse these (code reuse) *) let process_assign_ternop ~accu_op ~lhs ~tern_op ~rhs1 ~rhs2 ~rhs3 ?projections ~proj_in_scope @@ -1306,10 +1306,10 @@ let translate ?ident_label (expr : expression) : result = let elements = expr :: List.map ~f:snd exprs |> List.map ~f:(function - | { pexp_desc = Pexp_constant (Pconst_string _); _ } as s -> s - | [%expr [%e? t].value] -> [%expr Ir.Tnode.debug_name [%e t].value] - | [%expr [%e? t].grad] -> [%expr Ir.Tnode.debug_name [%e t].value ^ ".grad"] - | t -> [%expr Ir.Tnode.debug_name [%e t].value]) + | { pexp_desc = Pexp_constant (Pconst_string _); _ } as s -> s + | [%expr [%e? t].value] -> [%expr Ir.Tnode.debug_name [%e t].value] + | [%expr [%e? t].grad] -> [%expr Ir.Tnode.debug_name [%e t].value ^ ".grad"] + | t -> [%expr Ir.Tnode.debug_name [%e t].value]) in let res2 = loop ~proj_in_scope expr2 in let block = @@ -1591,18 +1591,18 @@ let translate ?ident_label (expr : expression) : result = let proj_in_scope = proj_in_scope || List.exists args ~f:(function - | { pparam_desc = Pparam_val ((Labelled s | Optional s), _, _); _ } - when String.equal s "projections" -> - true - | _ -> false) + | { pparam_desc = Pparam_val ((Labelled s | Optional s), _, _); _ } + when String.equal s "projections" -> + true + | _ -> false) in let bad_pun_hints = Set.union_list (module String) @@ bad_pun_hints :: List.map args ~f:(fun arg -> - match arg.pparam_desc with - | Pparam_val (_, _, pat) -> collect_pat_idents pat - | _ -> Set.empty (module String)) + match arg.pparam_desc with + | Pparam_val (_, _, pat) -> collect_pat_idents pat + | _ -> Set.empty (module String)) in let result = match body with Warning: Invalid documentation comment: File "tensor/row.ml", line 795, characters 39-49: '{ var; _ }': bad markup. Suggestion: did you mean '{! var; _ }' or '[ var; _ ]'? File "arrayjit/lib/low_level.ml", line 1, characters 0-0: diff --git a/_build/default/arrayjit/lib/low_level.ml b/_build/default/arrayjit/lib/.formatted/low_level.ml index 4e2ca58..41da273 100644 --- a/_build/default/arrayjit/lib/low_level.ml +++ b/_build/default/arrayjit/lib/.formatted/low_level.ml @@ -372,7 +372,7 @@ let visit_llc traced_store ~merge_node_id reverse_node_map ~max_visits llc = if (not virtualize_settings.inline_complex_computations) || Option.value_map access_pos ~default:true ~f:(fun pos -> - not ([%equal: int array] pos at_pos)) + not ([%equal: int array] pos at_pos)) then Hashtbl.update traced.accesses at_pos ~f:(visit ~is_assigned:(traced.zeroed_out || Hash_set.mem traced.assignments at_pos)) @@ -712,11 +712,11 @@ let%track7_sexp inline_computation ~id let computations = Hashtbl.find computations_table traced.tn |> Option.value_or_thunk ~default:(fun () -> - raise - @@ Utils.User_error - [%string - "Stale optimize_ctx: No computations found for #%{traced.tn.Tn.id#Int}: \ - %{Tn.debug_name traced.tn}"]) + raise + @@ Utils.User_error + [%string + "Stale optimize_ctx: No computations found for #%{traced.tn.Tn.id#Int}: \ + %{Tn.debug_name traced.tn}"]) in let body = List.rev_filter_map ~f:loop_proc computations in if List.is_empty body then raise @@ Non_virtual 14 else Some (unflat_lines body) dune build @fmt failed "/usr/bin/env" "bash" "-c" "opam exec -- dune build @fmt --ignore-promoted-rules || (echo "dune build @fmt failed"; exit 2)" failed with exit status 2 2025-11-13 21:05.09: Job failed: Failed: Build failed