Commit Graph
513 Commits
Author SHA1 Message Date
chenyuandGitHub cf6fff13aa OptOps.GROUP is OptOps.LOCAL (#17873) 2026-08-31 23:30:42 -04:00
chenyuandGitHub b87159cee1 delete dead OptOps tests (#17872) 2026-08-31 22:44:42 -04:00
chenyuandGitHub a3bde519d6 merge OptOps.UNROLL and OptOps.UPCAST (#17867)
* merge OptOps.UNROLL and OptOps.UPCAST

* why are convs so slow?
2026-08-31 21:50:05 -04:00
George HotzandGitHub 60cc1d7827 add Ops.RETURNED, remove TUPLE/GETTUPLE (#17804)
* delete Ops.FUNCTION/GETTUPLE/TUPLE: call outputs are AFTER on RETURNED placeholders

value-producing calls: the body is a plain parametric program that stores outputs
into output PARAMs (slots after the input PARAMs). the RETURNED placeholders are
inputs to the call, bound to the output PARAMs positionally wherever the call is
resolved, and callers AFTER on them like normal buffers. gradient flows through
the generic AFTER rule; everything is just Ops.CALL.

* RETURNED identity is its placement in the call srcs, not a nonce

slot=-1 merging collapses duplicate-signature outputs into one uop (t+1,t+2 grads
and multi-grad backward calls dedupe wrongly), and skipping the uop cache breaks
schedule_cache (stale linear hits since structural keys assume interning). instead
the RETURNED's placement (output index among call srcs) is its identity: identical
call constructions merge deterministically, positions never collide.

* resolve RETURNED afters in the tensor graph like values (master parity with gettuple)

- remove the CONTIGUOUS wrap of tagged call-output afters, it forced call outputs
  (e.g. local shard amax) into their own buffer/kernel instead of inlining
- inline RETURNED afters at transform time via returned_after_finalize, dissolving
  to values for consumers; calls with bound-variable or unresolved UNSHARD args
  keep the schedule-time resolution path
- allow movement ops (flat-storage views) in kernel graph value positions in the spec
- port embedding backward + extra/llama_kernels (local_abs_max, rmsnorm) to the new API

* use SINK, not GROUP, for gradient value containers

spec.py only blesses GROUP of stores/groups/loops; the gradient value bundles
(the forward values, root_grad seeds, and the after->call gradient edge) are
plain value containers, and SINK-of-values is already in the spec.

also fix extra/llama_kernels/rmsnorm: returned_outputs is a property

* CALL is positional: RETURNS work in any src position, convention lives in call_outputs

- all resolution paths (gradient, precompile transform, binding) locate RETURNEDs
  by identity, not by "last srcs"; only call_outputs builds the args-first layout
- grad_fxn padding aligns grads with the call's actual src positions
- add test_two_return/precompiled

* source-compat shim for maketuple/gettuple so foreign code built before the redesign keeps working

UOp.maketuple returns a _LegacyTupleValues holder; .call builds call_outputs;
CALL.gettuple(i) is returned_outputs[i]. the produced graphs are identical to
the new-api versions, so nn/extra/mlperf code is reverted to upstream text

* simplify function.py call construction + drop the resolved-call cache

- function.py: single and tuple returns both build the call through call_outputs
- tensor.py: resolve_function is deterministic and interned, the global cache was unneeded

* bind zero-offset views of flat storage to the storage instead of padding them

call args need offset 0 and enough length, not views: flat_storage collapses the
zero-offset contiguous view chain to the sized storage base, so resolved call args
are storage-bare like master (no PAD/SHRINK chains in the kernel graph)

* spec.py: drop stray rebase-collision edits, keep only the RETURNED changes

* test_multitensor: revert to master, the gettuple shim covers it

* materialize all tagged RETURNED afters into real buffers

call outputs need real storage regardless of whether they are finals of the current
realize: deferred/stateful outputs (the fp8 grad-amax mailbox) are consumed by later
realize steps as call args, where a resolved value would have no ranges

* call input buffers: wrap RETURNED-based afters, not real-buffer afters

precompiled call input binding kept any AFTER unwrapped; an AFTER on a RETURNED
placeholder has no storage behind it, so its value leaked into the kernel graph with
no consumer able to register ranges (llama3 8B fp8 mailbox pipeline crash).
materialize afters whose base has no buffer identity instead.

this was the fix matching master for the REDUCE-has-no-ranges crash and restores
the llama-kernels amax kernel count

* call slots are src positions, always; never rearrange

one upstream cause behind the three P1 findings: the raw CALL machinery binds
positionally (resolve_function params, gradient padding) but a second args-first
convention crept in where RETURNEDs get moved to trailing slots. position is
identity now:

- transform_precompiled_call keeps RETURNEDs' original src positions: outs take
  their places, other args become input buffers; no slot renumbering
- implicit gradients are emitted aligned to original src positions (None at
  RETURNED positions)
- flat_storage drops the hand-rolled contiguity analysis: reshape itself is the
  flat-prefix check (it raises ValueError); strided views materialize first

* nits on call slot positions; regression tests for interspersed RETURNED

- flat_storage back to pad_to().reshape() (reshape keeps movement views, it is not a contiguity check)
- input_buffer checks has_buffer_identity(after_ok=True)
- TestArgOrder: interspersed RETURNED (plain + precompiled transform), its gradient,
  padded and strided function inputs

* device fixes

* TestArgOrder: padded regression uses zero-start padded/shrunk view

* TestArgOrder: clone to force buffer identity in padded/strided regression tests

* slim: revert prepare formatting, drop reverted-bug tests, restore viz guards, clean comments, mirror returned on param

* gut transform_precompiled_call, delete returned_after_finalize

the transform keeps master's shape; the prepare-stage resolve_AFTER rule already
inlines plain call outputs, and materialization is owned by the input-buffer rule
(afters on real buffers bind, afters on RETURNEDs contiguous)

* update spec for returned

* transform_precompiled_call: inline the input-buffer rule, drop sorted() (body stores are already slot-ordered)

* drop dead RETURNED-era rules: prepare's after-shell strip (leftover from returned_after_finalize, which is gone), redundant pattern-covered SINK check, defensive slot-sorts (bodies are slot-ordered by construction)

* drop final_tags: final outputs of value calls materialize at sink construction

The set of finals is already known precisely (the big_sink's srcs), so track
nothing: wrap each final AFTER-on-RETURNED in CONTIGUOUS right after numbering.
Precompiled calls are excluded - transform_precompiled_call in the flatten
pass gives their outputs real buffers, and wrapping before that transform
leaves a stale tag that breaks the output copy.

* drop unused default_dtype import
2026-08-31 08:51:49 -07:00
George HotzandGitHub 812d5cef62 delete Ops.FUNCTION (#17824)
* delete Ops.FUNCTION: value-producing calls are just CALLs with a TUPLE body

a CALL with a TUPLE body (always void dtype) is value-producing and gradient-able,
outputs are extracted with GETTUPLE like before; all other CALLs are opaque.
TUPLE/GETTUPLE are untouched

* match the TUPLE body in the UPat, not in the rewrite

* remove FUNCTION from tinyspec (regen pdf) and viz

* fix and spec
2026-08-28 15:54:58 -07:00
chenyuandGitHub 086f45cb81 dtype is not a UOp field anymore (#17821) 2026-08-28 16:17:29 -04:00
chenyuandGitHub bd2711b7c1 put dtype to Ops.INS arg (#17817) 2026-08-28 15:05:17 -04:00
George HotzandGitHub 6b361e4de7 move shape into arg for param/buffer (#17783)
* move shape into arg for param/buffer

* no param_from_shape

* drop gratuitous syntax changes

* image is a in-graph view, folded into the param arg at render; drop dead multi param sharding

* view_as helper, simpler resolve_function, spec update

* spec: param/buffer are flat storage, no shape input

* image dims live in the param arg from transform_to_image; tighten kernel graph spec

* kernel graph spec: only RESHAPE/SHRINK over storage values, not all movement

* kernel graph: call args are storage, not views (pm_no_view_args); assert in spec

* strip views at the kernel graph level (pm_no_views), move into rangeify

* touchups
2026-08-27 18:13:24 -07:00
George HotzandGitHub f267a49639 UOp.param accepts single sint as shape (int,) (#17784)
* UOp.param accepts single sint as shape (int,)

Change UOp.param signature from shape:tuple[sint, ...]|None to shape:tuple[sint, ...]|sint|None.
A single sint means 1D shape (sint,). Update all callers from (n,) to n syntax.
No param_from_shape — multi-dim shapes stay as tuples.

* use single int syntax in hcq2 copy_with_kernel
2026-08-27 14:07:33 -07:00
chenyuandGitHub 4bdc865131 delete unused rewrite rules [PR] (#17748) 2026-08-26 10:50:42 -04:00
b1tgandGitHub 9860e5d285 llm tokenizer: fix tekken, add gpt4o (#17733) 2026-08-25 23:30:35 -07:00
George HotzandGitHub dc04c7820e lil fixes from new_rangeify (#17741)
* lil fixes from new_rangeify

* gpt sol review
2026-08-25 17:15:28 -07:00
chenyuandGitHub 6ece327cf3 CUSTOM arg is (str, dtype) [PR] (#17737) 2026-08-25 20:15:06 -04:00
chenyuandGitHub 9f01775cf4 dtype_from_uop for THREEFRY and FDIV (#17727) 2026-08-25 08:43:59 -04:00
chenyuandGitHub 9607787ce1 delete more explicitly set dtype to UOp [PR] (#17726)
* delete more explicitly set dtype to UOp [PR]

* not that
2026-08-25 08:32:45 -04:00
George HotzandGitHub a5678317c2 split rangeify to prepare.py (#17722) 2026-08-24 19:12:13 -07:00
chenyuandGitHub a7df1a1ace const are weak 3 [pr] (#17695) 2026-08-24 20:32:57 -04:00
chenyuandGitHub 8b164aefea test update from weak const (#17689) 2026-08-23 17:30:16 -04:00
chenyuandGitHub 356f665377 test update for weak const (#17675) 2026-08-21 21:50:29 -04:00
chenyuandGitHub daa154aa22 FLOORDIV to SHR for powers of 2 [pr] (#17669) 2026-08-21 16:28:04 -04:00
chenyuandGitHub 8f9cbdf0cc few more self folding [pr] (#17657) 2026-08-21 15:21:28 -04:00
chenyuandGitHub 554d078ac4 fix render_marg [pr] (#17656) 2026-08-21 10:03:22 -04:00
qazalandGitHub 1c3c9e96f6 remove setUp from test_sqtt_profiler (#17652)
* remove setUp from test_sqtt_profiler

* remove that

* cleaner

* do not need that
2026-08-21 17:29:11 +09:00
qazalandGitHub e8a8d99b99 profiler tracing using unique keys (#17651)
* profiler tracing using unique keys

* cleaner + comment
2026-08-21 17:06:01 +09:00
qazalandGitHub dcc2d021e7 prereq viz cleanups for unique profile keys (#17649)
* cleaner

* just use VIZ=-2

* better
2026-08-21 16:18:25 +09:00
qazalandGitHub 80bf60d782 profiler failing test for non unique kernel names (#17647)
* err

* expected
2026-08-21 13:52:35 +09:00
George HotzandGitHub 3fdbb82bfe add ansipad and PARALLEL contextvar (#17642) 2026-08-20 16:26:02 -07:00
chenyuandGitHub 592e3f8363 update const selector where folding [pr] (#17640)
folding a strong dtype WHERE to a weak const branch keeps the strong dtype
2026-08-20 18:49:34 -04:00
sirhcmandGitHub 3715006a21 fix float_to_bf16 on non-float32 inputs (#17638) 2026-08-20 18:14:30 -04:00
chenyuandGitHub e6324d1e1c test updates from weak const branch (#17618) 2026-08-19 22:56:25 -04:00
sirhcmandGitHub 2067133732 cpu: link with rt (#17608) 2026-08-19 17:55:08 -04:00
chenyuandGitHub fc214da417 test updates for weak const change (#17606) 2026-08-19 15:56:01 -04:00
chenyuandGitHub b8cc74ecf8 no float in tensor shape [pr] (#17605) 2026-08-19 15:40:16 -04:00
chenyuandGitHub c218b4842d fold_bitcast should truncate its input [pr] (#17601) 2026-08-19 14:39:36 -04:00
chenyuandGitHub bd6e70ac15 delete stale tests (#17596) 2026-08-19 11:18:05 -04:00
chenyuandGitHub 9550378704 finish casted_consts migration [PR] (#17595) 2026-08-19 10:43:55 -04:00
chenyuandGitHub b3e2f17b24 update NULL tests that depends on strong dtype CONST (#17594) 2026-08-19 10:26:38 -04:00
chenyuandGitHub 68b4407fe3 casted CONST migration for cstyle [pr] (#17587) 2026-08-19 09:01:40 -04:00
George HotzandGitHub c31038ff37 use KernelCountException when kernel count is being compared (#17584) 2026-08-18 16:06:03 -07:00
chenyuandGitHub 34c9b9d434 add back cast where rule [pr] (#17572) 2026-08-17 15:27:20 -04:00
chenyuandGitHub 138fb4a783 delete dead DType.scalar [PR] (#17561) 2026-08-16 21:12:17 -04:00
chenyuandGitHub 26cbadd69a no pm_fold_cast_const in full_rewrite_to_sink [PR] (#17547) 2026-08-15 10:18:59 -04:00
chenyuandGitHub 4b0525e594 no pm_fold_cast_const in UOp.simplify and hcq2 [pr] (#17540) 2026-08-14 21:39:47 -04:00
chenyuandGitHub 13c381b0c0 remove pm_fold_cast_const from initial symbolic [pr] (#17535)
interestingly it gives more accurate numerics when composing const like log10
2026-08-14 14:14:40 -04:00
chenyuandGitHub 80169c6758 remove where push cast to branches from sym [pr] (#17533)
* remove where push cast to branches from sym [pr]

not really needed and one less place that generates casted weak const when it's not needed

* fix
2026-08-14 12:57:56 -04:00
George HotzandGitHub b1859805b1 remove Ops.BIND (#17511)
* remove Ops.BIND

* param arg

* simplify that

* simplify

* cleaner

* props, not functions

* param and buffer can share
2026-08-13 23:52:16 -07:00
RaineandGitHub de04781b36 simplify equivalent const max (#17505)
* add const max folds

* add regression test

* move
2026-08-12 08:39:29 -07:00
sirhcmandGitHub 479ffb0cda remove Ops.SLICE (#17492) 2026-08-11 18:50:04 -04:00
George HotzandGitHub d4d537c8ae add SPEC checking for the kernel graph (#17432)
* add SPEC checking for the kernel graph

* skip test

* raise there, not None

* handwritten

* issue with unshard

* multi works

* and bitcast

* fix new tests

* fix linear

* remove call index

* fix shrink

* fixes
2026-08-08 10:00:06 -07:00
chenyuandGitHub 4a3b8f6501 better _drop_valid_stmts [pr] (#17454) 2026-08-07 15:18:35 -04:00