-
Notifications
You must be signed in to change notification settings - Fork 12k
ggml : add ggml_fill() #13772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
ggml : add ggml_fill() #13772
Conversation
Co-authored-by: Sigbjørn Skjæret <sigbjorn.skjaeret@scala.com>
Inplace operations are a bit tricky (#12757 (comment)), so I am a bit hesitating. Wondering if there is some other way to support this.
Such tensors should always be marked as inputs and set via the
There isn't a convenient way to do it. Probably: val = ggml_new_tensor(1 element);
ggml_set_input(val);
...
aux = ggml_repeat(val, [needed size])
cur = ggml_cpy(aux, ggml_view(...));
ggml_build_forward_expand(gf, cur); |
If we don't want to support inplace, we can internally create new tensor, so Setting it via an input can be a bit annoying especially in the case I want to use just one single number:
Another way could be to provide a (But ofc having something like pytorch's |
Thinking more about it, my concern might not be very relevant because in this case we don't use the existing data as input - i.e. we always override it with a specific value that does not depend on the input. So it's probably OK. Maybe we should just improve the API a bit to become more type-safe. For example, what happens if you |
Hmm I think it's currently the same concern as many other ops like But the idea of supporting I32 type is interesting. Don't know if asking this is too much, but since a long time now I really want If |
The implementation of |
The issue of creating a new tensor in a graph with Adding a version of this op that returns a new tensor instead of a view would be trivial, and would avoid this issue. Just make a |
Add
ggml_fill(ctx0, tensor, value)
which mimic the idea of pytorchfull
,full_like
,zero_likes
,ones_likes
It's not 100% equivalent to pytorch, as this is an in-place operation. However, it allow much more flexibility. For example:
new_tensor
, thenfill
view
, thenfill
*_like
behavior by doing adup
, thenfill
For simplification, this op is single-threaded, CPU-only for now