Skip to content

ggml : add ggml_interpolate_sf() with explicit scale factors#22036

Closed
ManaEstras wants to merge 1 commit into
ggml-org:masterfrom
ManaEstras:pr1-interpolate-sf
Closed

ggml : add ggml_interpolate_sf() with explicit scale factors#22036
ManaEstras wants to merge 1 commit into
ggml-org:masterfrom
ManaEstras:pr1-interpolate-sf

Conversation

@ManaEstras
Copy link
Copy Markdown
Contributor

Overview

Add ggml_interpolate_sf() API that accepts explicit scale factors for interpolation operations.

Motivation

The existing ggml_interpolate() computes scale factors internally as ne_dst / ne_src. However, some vision-language models require interpolation with scale factors that cannot be expressed as simple dimension ratios.

For example, when interpolating position embeddings, a model may use:

scale_factor = (target_dim + offset) / base_grid_size

where offset is a learned or configured value (e.g., 0.1). This cannot be achieved by manipulating input/output tensor dimensions alone.

This PR introduces ggml_interpolate_sf() which allows the caller to specify sf0 and sf1 directly, enabling exact control over the interpolation coordinate mapping.

Changes

API:

  • Add ggml_interpolate_sf(ctx, a, ne0, ne1, ne2, ne3, mode, sf0, sf1)
  • Add GGML_SCALE_FLAG_CUSTOM_SF flag

Backend support:

  • CPU, CUDA, Metal, SYCL, Vulkan, OpenCL

Bug fix:

  • Fix out-of-bounds access in nearest interpolation when custom scale factors cause source index overflow

Tests:

  • Add 38 test cases covering upscale, downscale, non-square inputs, and various interpolation modes

Testing

  • 38 interpolate_sf tests pass on CPU
  • 38 interpolate_sf tests pass on Metal
  • ctest -L main passes

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - AI assisted with code review and documentation drafting. All code was human-authored and manually reviewed.

- add ggml_interpolate_sf() API for explicit scale factor interpolation
- add GGML_SCALE_FLAG_CUSTOM_SF flag
- add support across all backends (CPU, CUDA, Metal, SYCL, Vulkan, OpenCL)
- fix nearest interpolation out-of-bounds access
- add 38 test cases for interpolate_sf in test-backend-ops
@ggml-gh-bot
Copy link
Copy Markdown

ggml-gh-bot Bot commented Apr 17, 2026

Hi @ManaEstras, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • Multiple open PRs from a new contributor: We limit new contributors (those without a previously merged PR) to 1 open PR at a time. You currently have 3 open PRs.

  • Multiple backend changes in one PR: When adding support for a new model or feature, focus on CPU support only in the initial PR. Add support for other backends like CUDA in follow-up PRs. If you have a good reason to modify multiple backends in one PR, please explain it.


Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@github-actions github-actions Bot added testing Everything test related Nvidia GPU Issues specific to Nvidia GPUs Vulkan Issues specific to the Vulkan backend ggml changes relating to the ggml tensor library for machine learning SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language Apple Metal https://en.wikipedia.org/wiki/Metal_(API) OpenCL Issues specific to the OpenCL backend labels Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Apple Metal https://en.wikipedia.org/wiki/Metal_(API) ggml changes relating to the ggml tensor library for machine learning Nvidia GPU Issues specific to Nvidia GPUs OpenCL Issues specific to the OpenCL backend SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language testing Everything test related Vulkan Issues specific to the Vulkan backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants