-
Notifications
You must be signed in to change notification settings - Fork 5
ggml_scale_bias #27
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
ggml_scale_bias #27
Changes from all commits
50f88fc
7af3fd9
a5ccf16
e427af7
92a8738
a28df6f
782b58f
477a97a
0e51a0a
4d01953
b22708f
c8d8931
265cb43
563aca0
50c678f
0d70ca8
4ea74b0
cd1703a
ebbad77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3069,12 +3069,14 @@ static struct ggml_tensor * ggml_scale_impl( | |
| struct ggml_context * ctx, | ||
| struct ggml_tensor * a, | ||
| float s, | ||
| float b, | ||
| bool inplace) { | ||
| GGML_ASSERT(ggml_is_padded_1d(a)); | ||
|
|
||
| struct ggml_tensor * result = inplace ? ggml_view_tensor(ctx, a) : ggml_dup_tensor(ctx, a); | ||
|
|
||
| ggml_set_op_params(result, &s, sizeof(s)); | ||
| float params[2] = { s, b }; | ||
| ggml_set_op_params(result, ¶ms, sizeof(params)); | ||
|
|
||
| result->op = GGML_OP_SCALE; | ||
| result->src[0] = a; | ||
|
|
@@ -3086,14 +3088,30 @@ struct ggml_tensor * ggml_scale( | |
| struct ggml_context * ctx, | ||
| struct ggml_tensor * a, | ||
| float s) { | ||
| return ggml_scale_impl(ctx, a, s, false); | ||
| return ggml_scale_impl(ctx, a, s, 0.0, false); | ||
| } | ||
|
|
||
| struct ggml_tensor * ggml_scale_inplace( | ||
| struct ggml_context * ctx, | ||
| struct ggml_tensor * a, | ||
| float s) { | ||
| return ggml_scale_impl(ctx, a, s, true); | ||
| return ggml_scale_impl(ctx, a, s, 0.0, true); | ||
| } | ||
|
|
||
| struct ggml_tensor * ggml_scale_bias( | ||
| struct ggml_context * ctx, | ||
| struct ggml_tensor * a, | ||
| float s, | ||
| float b) { | ||
| return ggml_scale_impl(ctx, a, s, b, false); | ||
| } | ||
|
|
||
| struct ggml_tensor * ggml_scale_bias_inplace( | ||
| struct ggml_context * ctx, | ||
| struct ggml_tensor * a, | ||
| float s, | ||
| float b) { | ||
| return ggml_scale_impl(ctx, a, s, b, true); | ||
| } | ||
|
|
||
| // ggml_set | ||
|
|
@@ -5777,7 +5795,7 @@ static void ggml_compute_backward( | |
| } break; | ||
| case GGML_OP_MEAN: { | ||
| if (src0_needs_grads) { | ||
| ggml_add1_or_set(ctx, cgraph, isrc0, ggml_scale_impl(ctx, grad, 1.0f/src0->ne[0], false)); | ||
| ggml_add1_or_set(ctx, cgraph, isrc0, ggml_scale_impl(ctx, grad, 1.0f/src0->ne[0], 0.0, false)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify consistency across all backend implementations. The backward pass correctly maintains existing behavior by passing 🏁 Script executed: #!/bin/bash
# Verify that backend implementations handle the new parameter format
echo "Checking backend implementations for scale operation parameter handling..."
# Search for scale operation implementations in backends
rg -A 10 -B 5 "GGML_OP_SCALE" ggml/src/ggml-*/
# Look for parameter extraction patterns that might need updating
rg -A 5 "op_params.*scale\|scale.*op_params" ggml/src/ggml-*/Length of output: 26206 Review CPU & other backends for updated SCALE op parameter handling Let’s confirm that every frontend now reads both
🏁 Script executed: #!/bin/bash
# Verify SCALE op uses both scale & bias params in each backend
grep -n "ggml_compute_forward_scale" ggml/src/ggml-cpu/ggml-cpu.c
grep -n "ggml_cuda_op_scale" ggml/src/ggml-cuda/ggml-cuda.cu
grep -n "ggml_cl_scale" ggml/src/ggml-opencl/ggml-opencl.cpp
grep -n "ggml_sycl_scale" ggml/src/ggml-sycl/ggml-sycl.cpp
grep -n "case GGML_OP_SCALE" ggml/src/ggml-metal/ggml-metal.m
grep -n "ggml_vk_scale" ggml/src/ggml-vulkan/ggml-vulkan.cppLength of output: 1063 To confirm each backend correctly reads both 🏁 Script executed: #!/bin/bash
# CPU: ggml_compute_forward_scale
sed -n '1770,1840p' ggml/src/ggml-cpu/ggml-cpu.c
# CUDA: ggml_cuda_op_scale
sed -n '2350,2450p' ggml/src/ggml-cuda/ggml-cuda.cu
# OpenCL: ggml_cl_scale
sed -n '5560,5660p' ggml/src/ggml-opencl/ggml-opencl.cpp
# SYCL: ggml_sycl_scale
sed -n '3500,3600p' ggml/src/ggml-sycl/ggml-sycl.cpp
# Metal: first GGML_OP_SCALE case
sed -n '1700,1800p' ggml/src/ggml-metal/ggml-metal.m
# Vulkan: ggml_vk_scale
sed -n '7480,7600p' ggml/src/ggml-vulkan/ggml-vulkan.cpp
# CANN: ggml_cann_scale
grep -R -n "ggml_cann_scale" -n ggml/src/ggml-cann
sed -n '1,200p' ggml/src/ggml-cann/ggml-cann.cppLength of output: 32299 To confirm each backend actually reads both 🏁 Script executed: #!/bin/bash
set -e
echo "CPU: locate compute_forward_scale definition"
grep -R -n "void ggml_compute_forward_scale" -n ggml/src/ggml-cpu/ggml-cpu.c || echo "not found"
echo
echo "CUDA: locate ggml_cuda_op_scale definition"
grep -R -n "void ggml_cuda_op_scale" -n ggml/src/ggml-cuda/ggml-cuda.cu || echo "not found"
echo
echo "SYCL: locate ggml_sycl_op_scale definition"
grep -R -n "void ggml_sycl_op_scale" -n ggml/src/ggml-sycl/ggml-sycl.cpp || echo "not found"
echo
echo "Metal: find kernel args for SCALE"
grep -R -n "kernel_scale" -n ggml/src/ggml-metal/ggml-metal.m || echo "not found"
grep -R -n "float scale" -n ggml/src/ggml-metal/ggml-metal.m || echo "not found"
echo
echo "CANN: inspect aclnn_ops implementation"
sed -n '340,430p' ggml/src/ggml-cann/aclnn_ops.cppLength of output: 4783 Ensure SCALE op consumes both scale & bias in every backend We’ve added a second
OpenCL, Metal, and Vulkan already handle 🤖 Prompt for AI Agents |
||
| } | ||
| } break; | ||
| case GGML_OP_REPEAT: { | ||
|
|
@@ -5854,7 +5872,7 @@ static void ggml_compute_backward( | |
| if (src0_needs_grads) { | ||
| float s; | ||
| memcpy(&s, tensor->op_params, sizeof(float)); | ||
| ggml_add_or_set(ctx, cgraph, isrc0, ggml_scale_impl(ctx, grad, s, false)); | ||
| ggml_add_or_set(ctx, cgraph, isrc0, ggml_scale_impl(ctx, grad, s, 0.0, false)); | ||
| } | ||
| } break; | ||
| case GGML_OP_SET: { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.