[GH-ISSUE #877] Can't import model: invalid version #62460

Closed
opened 2026-05-03 09:02:45 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @olafgeibig on GitHub (Oct 23, 2023).
Original GitHub issue: https://github.com/ollama/ollama/issues/877

Problem

I tried to import agentlm-7b.Q5_K_M.gguf from TheBloke but it fails. I can run the same file successfully with llama.cpp

Command line

ollama create agentlm:7b-Q5_K_M -f agentlm.ollama

Output

parsing modelfile
looking for model
⠋ creating model layer  Error: invalid version

Model file

FROM ./agentlm-7b.Q5_K_M.gguf
TEMPLATE """
[INST] <<SYS>>
{{ .System }}
<</SYS>>
{{ .Prompt }} [/INST]
"""

Environment

MacBook Pro M1 16GB, MacOS 13.3.1
Ollama 0.1.3

Originally created by @olafgeibig on GitHub (Oct 23, 2023). Original GitHub issue: https://github.com/ollama/ollama/issues/877 ## Problem I tried to import [agentlm-7b.Q5_K_M.gguf](https://huggingface.co/TheBloke/agentlm-7B-GGUF/blob/main/agentlm-7b.Q5_K_M.gguf) from TheBloke but it fails. I can run the same file successfully with llama.cpp ### Command line ```ollama create agentlm:7b-Q5_K_M -f agentlm.ollama``` ### Output ``` parsing modelfile looking for model ⠋ creating model layer Error: invalid version ``` ## Model file ``` FROM ./agentlm-7b.Q5_K_M.gguf TEMPLATE """ [INST] <<SYS>> {{ .System }} <</SYS>> {{ .Prompt }} [/INST] """ ``` ## Environment MacBook Pro M1 16GB, MacOS 13.3.1 Ollama 0.1.3
GiteaMirror added the bug label 2026-05-03 09:02:46 -05:00
Author
Owner

@deichbewohner commented on GitHub (Oct 23, 2023):

I have observed that some of the newer models from TheBloke are employing the GGUF container specification version 3.

I executed a fmt.Println(c.Version) at this location: /llm/gguf.go#L31.
This yielded a 3 in the log.

Nonetheless, the referenced code currently only accommodates GGUF version 1 or 2.

Edit:

<!-- gh-comment-id:1775373544 --> @deichbewohner commented on GitHub (Oct 23, 2023): I have observed that some of the newer models from TheBloke are employing the GGUF container specification version 3. I executed a `fmt.Println(c.Version)` at this location: [/llm/gguf.go#L31](https://github.com/jmorganca/ollama/blob/ccff9ca09c1fb6709ba4456f0285b97bd5db9599/llm/gguf.go#L31). This yielded a `3` in the log. Nonetheless, the [referenced code](https://github.com/jmorganca/ollama/blob/ccff9ca09c1fb6709ba4456f0285b97bd5db9599/llm/gguf.go#L32) currently only accommodates GGUF version 1 or 2. Edit: - The relevant commit in llama.cpp should be this: https://github.com/ggerganov/llama.cpp/commit/8cf19d60dc93809db8e51fedc811595eed9134c5#diff-cbcdffc2972ef722e13636e19e95da7648bd8d5be17535e013ca8edf77200228 - You can check the model version with `xxd -l 5 -p agentlm-13b.Q5_K_M.gguf` (the last byte is the version number)
Author
Owner

@deichbewohner commented on GitHub (Oct 23, 2023):

Upon reading the GGUF changes in the llama.cpp commit mentioned in my previous comment, it appears that there are no format changes, at least on a LittleEndian machine. I have made a temporary modification to the Ollama code here to accommodate the new version as follows:

switch c.Version {
    case 1:
        binary.Read(r, binary.LittleEndian, &c.V1)
    case 2, 3:
        binary.Read(r, binary.LittleEndian, &c.V2)
}

With this adjustment, the new models function correctly. However, this is clearly a workaround and not a permanent solution. A more robust implementation should be considered, especially if there are updates to the llama.cpp submodule in the future.

<!-- gh-comment-id:1775470728 --> @deichbewohner commented on GitHub (Oct 23, 2023): Upon reading the GGUF changes in the llama.cpp commit mentioned in my previous comment, it appears that there are no format changes, at least on a LittleEndian machine. I have made a temporary modification to the Ollama code [here](https://github.com/jmorganca/ollama/blob/ccff9ca09c1fb6709ba4456f0285b97bd5db9599/llm/gguf.go#L32) to accommodate the new version as follows: ```go switch c.Version { case 1: binary.Read(r, binary.LittleEndian, &c.V1) case 2, 3: binary.Read(r, binary.LittleEndian, &c.V2) } ``` With this adjustment, the new models function correctly. However, this is clearly a workaround and not a permanent solution. A more robust implementation should be considered, especially if there are updates to the llama.cpp submodule in the future.
Author
Owner

@olafgeibig commented on GitHub (Oct 23, 2023):

Thank you for picking this up. xxd -l 5 -p agentlm-7b.Q5_K_M.gguf returns 4747554603

<!-- gh-comment-id:1775528561 --> @olafgeibig commented on GitHub (Oct 23, 2023): Thank you for picking this up. ```xxd -l 5 -p agentlm-7b.Q5_K_M.gguf``` returns 4747554603
Author
Owner

@deichbewohner commented on GitHub (Oct 23, 2023):

This Issue is now addressed and worked on in https://github.com/jmorganca/ollama/pull/881

<!-- gh-comment-id:1775686810 --> @deichbewohner commented on GitHub (Oct 23, 2023): This Issue is now addressed and worked on in https://github.com/jmorganca/ollama/pull/881
Author
Owner

@mxyng commented on GitHub (Oct 23, 2023):

As @deichbewohner mentioned, this is fixed in #881 and will be in the next reelase

<!-- gh-comment-id:1775715866 --> @mxyng commented on GitHub (Oct 23, 2023): As @deichbewohner mentioned, this is fixed in #881 and will be in the next reelase
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#62460