Skip to content

Optimizer precision - #135

Merged
marcelluethi merged 2 commits into
dimwit-dev:mainfrom
benikm91:optimizer-precision
Aug 2, 2026
Merged

Optimizer precision#135
marcelluethi merged 2 commits into
dimwit-dev:mainfrom
benikm91:optimizer-precision

Conversation

@benikm91

Copy link
Copy Markdown
Collaborator

No description provided.

@benikm91
benikm91 requested a review from marcelluethi July 21, 2026 21:19
@benikm91
benikm91 marked this pull request as draft July 21, 2026 21:20
@benikm91
benikm91 removed the request for review from marcelluethi July 21, 2026 21:20
@benikm91

Copy link
Copy Markdown
Collaborator Author

@marcelluethi As discussed today, I will add tests before we merge.

@marcelluethi

Copy link
Copy Markdown
Contributor

Thanks for implementing this. This looks like a very good solution to me.

@benikm91
benikm91 force-pushed the optimizer-precision branch from eac7a09 to b9f60f1 Compare July 31, 2026 08:23
@benikm91
benikm91 marked this pull request as ready for review August 1, 2026 09:55
@benikm91
benikm91 requested a review from marcelluethi August 1, 2026 09:55
def --![P](p1: P)(using TensorTree[P], FloatTree[P, V]): P = Tensor0(VType[V])(p2) --! p1
def **![P](p1: P)(using TensorTree[P], FloatTree[P, V]): P = Tensor0(VType[V])(p2) **! p1
def `//!`[P](p1: P)(using TensorTree[P], FloatTree[P, V]): P = Tensor0(VType[V])(p2) `//!` p1

@marcelluethi marcelluethi Aug 1, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this not be confusing on single tensors, as they are both tensor trees and tensors and consequently will have +, +! and ++!. Another problem might be that ! usually indicates broadcasting and has here a different meaning.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mostly mirrors what we have in ValueOps for Tensors. While I think we can improve this overall, I propose moving it to a future PR and merging it as is.

Currently:
+: Add two tensors of the same shape
+!: Add two tensors, broadcast lower-rank one
++: Add two tensor trees of the same structure
++!: Add Tensor0/Double to a tensor tree by broadcasting it for each structure

So, in my mind, ++! does broadcasting (just limited to Tensor0, as it is the only structure broadcastable to all Tensor shapes in the tree). But you are probably right that it's suboptimal; I think, as is, we can write "t0 ++! 5" but not "t0 +! 5" with t0 being Tensor0... Also, ValueOps provides Float extension methods, and FloatTree provides Double extension methods... Let's address this in a future clean-up.

@marcelluethi marcelluethi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. I think it is now the right way to handle the precision of the optimizers. I also like the optimizer parameters are just Double and hence easy to fix. The only thing I am not sure about are the !++ extension methods. However, I am fine with merging if this is not an accident but a conscious decision.

@marcelluethi
marcelluethi merged commit 26b8f4e into dimwit-dev:main Aug 2, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants