|
| 1 | +# LlamaCPP Fork Management Strategy |
| 2 | + |
| 3 | +## Problem Statement |
| 4 | + |
| 5 | +The team maintains a fork of llama.cpp with custom modifications but needs to stay synchronized with the rapidly evolving upstream repository. Traditional PR-based merging creates merge commits or squashes that modify git history, making future upstream synchronization difficult. |
| 6 | + |
| 7 | +## Proposed Solution |
| 8 | + |
| 9 | +### Branch Structure |
| 10 | + |
| 11 | +- **temp-upstream**: Tracks the official upstream llama.cpp repository (pure upstream) |
| 12 | +- **temp-latest**: Contains team's custom changes rebased on top of upstream |
| 13 | +- **Feature branches**: Built on top of temp-latest for new changes |
| 14 | + |
| 15 | +### Synchronization Process |
| 16 | + |
| 17 | +#### Initial Setup (one-time) |
| 18 | +To make things clear, will start from a blank state. You can skip steps you've already done: |
| 19 | + |
| 20 | +1. **Fork the repository**: Fork `qvac-ext-lib-llama.cpp` repo in GitHub (e.g., `https://github.com/olyasir/qvac-ext-lib-llama.cpp`) |
| 21 | + |
| 22 | +2. **Clone locally**: |
| 23 | + ```bash |
| 24 | + git clone [email protected]:olyasir/qvac-ext-lib-llama.cpp.git |
| 25 | + cd qvac-ext-lib-llama.cpp |
| 26 | + ``` |
| 27 | + |
| 28 | +3. **Configure remotes**: |
| 29 | + ```bash |
| 30 | + # Add upstream ggml remote |
| 31 | + git remote add ggml [email protected]:ggml-org/llama.cpp.git |
| 32 | + git fetch ggml |
| 33 | + |
| 34 | + # Add tether remote |
| 35 | + git remote add tether [email protected]:tetherto/qvac-ext-lib-llama.cpp.git |
| 36 | + git fetch tether |
| 37 | + ``` |
| 38 | + |
| 39 | +#### Regular Synchronization Process |
| 40 | + |
| 41 | +1. **Prepare temp-latest branch**: |
| 42 | + ```bash |
| 43 | + git checkout temp-latest |
| 44 | + git pull |
| 45 | + ``` |
| 46 | + |
| 47 | +2. **Rebase onto new upstream tag** (e.g., b6789): |
| 48 | + ```bash |
| 49 | + git rebase b6789 |
| 50 | + ``` |
| 51 | + |
| 52 | +3. **Resolve conflicts**: Git will stop if it finds conflicts. Resolve them as appropriate (may need to check with original writers) |
| 53 | + |
| 54 | +4. **Push rebased changes**: |
| 55 | + ```bash |
| 56 | + git push -f |
| 57 | + ``` |
| 58 | + |
| 59 | +5. **Create and push new tag**: |
| 60 | + ```bash |
| 61 | + git tag b6789.0.0 |
| 62 | + # Add description like "Sync with upstream version b6789" |
| 63 | + git push tether tag b6789.0.0 |
| 64 | + ``` |
| 65 | + |
| 66 | +6. **Test and publish**: Test the new tag, and if it works properly, publish to vcpkg |
| 67 | + |
| 68 | +#### Testing Process |
| 69 | + |
| 70 | +1. **Get test project**: Download the test project from [vcpkg-test-llama-cpp](https://drive.google.com/file/d/1Fm47_QsPsjp-kjPnQpQiRTE5KIrxMh_G/view?usp=sharing) (simple project that depends on the llama-cpp port) |
| 71 | + |
| 72 | +2. **Update vcpkg port**: |
| 73 | + ```bash |
| 74 | + # Copy latest ports/llama-cpp folder from qvac-registry-vcpkg |
| 75 | + cp -r qvac-registry-vcpkg/ports/llama-cpp vcpkg/ports/llama-cpp |
| 76 | + ``` |
| 77 | + |
| 78 | +3. **Update version**: In `vcpkg/ports/llama-cpp/vcpkg.json`, update version number to new tag (without 'b' prefix) |
| 79 | + - For tag `b6789.0.0` → version should be `6789.0.0` |
| 80 | + |
| 81 | +4. **Initial build attempt**: |
| 82 | + ```bash |
| 83 | + bare-make generate |
| 84 | + ``` |
| 85 | + |
| 86 | +5. **Fix SHA512 hash**: Configuration will fail with hash mismatch error: |
| 87 | + ``` |
| 88 | + error: download from https://github.com/tetherto/qvac-ext-lib-llama.cpp/archive/b6435.0.0.tar.gz had an unexpected hash |
| 89 | + note: Expected: 9baedc3c4ff681222d8fe16ac10346af9cd7fd5a4a6047448f8a3ad0712ba8e35dbd06af16b3a8c6c8b25518b43fd3b152275e90969f0c33cf851cdb44484eb0 |
| 90 | + note: Actual : c869a45e809c367cae6122bfc26c26f16767b010f2da804eb6d20eab8fc9ee8a6fa9c35d04792d0dc1e7483a1b552441027a96ebd30cfb8ac455a3da52801f59 |
| 91 | + ``` |
| 92 | + Update `vcpkg/ports/llama-cpp/portfile.cmake` - replace SHA512 line with the "Actual" value |
| 93 | + |
| 94 | +6. **Final verification**: |
| 95 | + ```bash |
| 96 | + bare-make generate |
| 97 | + bare-make build |
| 98 | + ``` |
| 99 | + If successful, the sync worked properly and you can publish the new vcpkg port version |
| 100 | + |
| 101 | +### Version Management |
| 102 | +*(on temp-latest branch)* |
| 103 | + |
| 104 | +- Base versions follow upstream tags (e.g., b5932) |
| 105 | +- Extended versions add incremental numbers: |
| 106 | + - **b5932.0.0**: temp-upstream + mtmd changes |
| 107 | + - **b5932.1.0**: temp-upstream + mtmd + load-from-buffer changes |
| 108 | + - And so on... |
| 109 | + |
| 110 | +## Development Workflow |
| 111 | + |
| 112 | +1. **New PRs**: Create against temp-latest (which contains existing custom changes) |
| 113 | +2. **After synchronization**: New PRs pointed to temp-latest should include all our changes and the new upstream version |
| 114 | +3. **vcpkg integration**: vcpkg registry points to specific commit hashes, not branch names |
| 115 | +4. **Testing**: Test new tags before publishing to vcpkg |
| 116 | + |
| 117 | +## Benefits |
| 118 | + |
| 119 | +This strategy ensures the team can maintain their custom modifications while staying current with upstream llama.cpp development. |
| 120 | + |
| 121 | +- Maintains clean git history aligned with upstream |
| 122 | +- Enables easy future synchronization with upstream |
| 123 | +- Protects against accidental direct merges to main |
| 124 | +- Allows multiple teams (including external collaborators like Collabora) to build on top of stable versions |
| 125 | +- Custom changes accumulate incrementally while staying current with upstream |
0 commit comments