Skip to content

iOS library is broken because ggml dependency is not pinned  #4867

Closed
@azarovalex

Description

@azarovalex

I was debugging some accidental crashes in SwiftUI sample, dug deeper and understood a couple of things.

Some background

  1. When llama.cpp is built outside of Xcode, e.g. with make, there is no direct dependency on ggml repo. ggml sources are just duplicated in this repo, they get out of sync but there are scripts used to sync two repos + whisper.cpp, which also use ggml.

  2. Xcode build is different (not only the sample, but all external applications that use llama.cpp through SPM). In this case ggml will be fetched from ggml repo, ignoring files present in this repo. Additionally, dependency on ggml repo is not pinned, which technically means that ggml can be resolved to any commit.

Why it's done like this and why it doesn't work

This difference in build logic between Xcode and make was introduced only recently in this PR.
I completely see the reasoning behind this change, indeed whisper.cpp already has it's own copy of ggml, so we got a conflict of sybmols in the resulting binary if we used both llama.cpp and whisper.cpp in one iOS app.

However the current approach just doesn't work for llama.cpp at all. For example right now latest master of llama.cpp (cd108e6) is not compatible with the latest master of ggml (c75db1e), it leads to a crash on this line.

Proposed solution

I really don't want to force Grigori to rethink how he structures his projects, in this case a monorepo might solve the problem, but I guess iOS build just has to adapt to the existing structure.
The best solution I see so far:

  • We create a new target in the SPM manifest. It will build llama.cpp exactly how make does it, using local ggml sources and without dependency on external repo. This new target becomes the recommended way to integrate llama.cpp to any iOS app, because it's guaranteed to always build the same sources as other build systems. (this step is basically a revert of Updates Package.swift to use ggml as dependency #4691)
  • For rare cases when an app already has ggml, like with whisper.cpp, we create a second target that uses ggml from the external repo and the developer of the app will be responsible for pinning a compatible version, ensuring two commits of llama and ggml work together. (This target is exactly the target we have right now)
  • Finally we add a CI job that builds the sample, so this won't happen again. 😄

I'd love to hear opinions on this possible solution from folks who previously contributed into SPM manifest: @ggerganov @1-ashraful-islam @kchro3 @jhen0409.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions