Skip to content

Commit deb1399

Browse files
authored
Merge branch 'ggml-org:master' into glm45v-2
2 parents 7d05d7c + c5023da commit deb1399

File tree

84 files changed

+3865
-930
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+3865
-930
lines changed

.devops/s390x.Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ RUN --mount=type=cache,target=/root/.ccache \
2424
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
2525
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
2626
-DLLAMA_BUILD_TESTS=OFF \
27-
-DGGML_BACKEND_DL=OFF \
2827
-DGGML_NATIVE=OFF \
28+
-DGGML_BACKEND_DL=ON \
29+
-DGGML_CPU_ALL_VARIANTS=ON \
2930
-DGGML_BLAS=ON \
3031
-DGGML_BLAS_VENDOR=OpenBLAS && \
3132
cmake --build build --config Release -j $(nproc) && \
@@ -103,6 +104,7 @@ FROM base AS light
103104
WORKDIR /llama.cpp/bin
104105

105106
# Copy llama.cpp binaries and libraries
107+
COPY --from=collector /llama.cpp/bin/*.so /llama.cpp/bin
106108
COPY --from=collector /llama.cpp/bin/llama-cli /llama.cpp/bin
107109

108110
ENTRYPOINT [ "/llama.cpp/bin/llama-cli" ]
@@ -116,6 +118,7 @@ ENV LLAMA_ARG_HOST=0.0.0.0
116118
WORKDIR /llama.cpp/bin
117119

118120
# Copy llama.cpp binaries and libraries
121+
COPY --from=collector /llama.cpp/bin/*.so /llama.cpp/bin
119122
COPY --from=collector /llama.cpp/bin/llama-server /llama.cpp/bin
120123

121124
EXPOSE 8080

.github/workflows/build-linux-cross.yml

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,49 @@ on:
44
workflow_call:
55

66
jobs:
7-
ubuntu-24-riscv64-cpu-cross:
8-
runs-on: ubuntu-24.04
7+
# ubuntu-24-riscv64-cpu-cross:
8+
# runs-on: ubuntu-24.04
99

10-
steps:
11-
- uses: actions/checkout@v4
12-
- name: Setup Riscv
13-
run: |
14-
sudo dpkg --add-architecture riscv64
10+
# steps:
11+
# - uses: actions/checkout@v4
12+
# - name: Setup Riscv
13+
# run: |
14+
# sudo dpkg --add-architecture riscv64
1515

16-
# Add arch-specific repositories for non-amd64 architectures
17-
cat << EOF | sudo tee /etc/apt/sources.list.d/riscv64-ports.list
18-
deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports/ noble main universe
19-
deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports/ noble-updates main universe
20-
deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports/ noble-security main universe
21-
deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports/ noble-backports main universe
22-
EOF
16+
# # Add arch-specific repositories for non-amd64 architectures
17+
# cat << EOF | sudo tee /etc/apt/sources.list.d/riscv64-ports.list
18+
# deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports/ noble main universe
19+
# deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports/ noble-updates main universe
20+
# deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports/ noble-security main universe
21+
# deb [arch=riscv64] http://ports.ubuntu.com/ubuntu-ports/ noble-backports main universe
22+
# EOF
2323

24-
sudo apt-get update || true ;# Prevent failure due to missing URLs.
24+
# sudo apt-get update || true ;# Prevent failure due to missing URLs.
2525

26-
sudo apt-get install -y --no-install-recommends \
27-
build-essential \
28-
gcc-14-riscv64-linux-gnu \
29-
g++-14-riscv64-linux-gnu
26+
# sudo apt-get install -y --no-install-recommends \
27+
# build-essential \
28+
# gcc-14-riscv64-linux-gnu \
29+
# g++-14-riscv64-linux-gnu
3030

31-
- name: Build
32-
run: |
33-
cmake -B build -DLLAMA_CURL=OFF \
34-
-DCMAKE_BUILD_TYPE=Release \
35-
-DGGML_OPENMP=OFF \
36-
-DLLAMA_BUILD_EXAMPLES=ON \
37-
-DLLAMA_BUILD_TOOLS=ON \
38-
-DLLAMA_BUILD_TESTS=OFF \
39-
-DCMAKE_SYSTEM_NAME=Linux \
40-
-DCMAKE_SYSTEM_PROCESSOR=riscv64 \
41-
-DCMAKE_C_COMPILER=riscv64-linux-gnu-gcc-14 \
42-
-DCMAKE_CXX_COMPILER=riscv64-linux-gnu-g++-14 \
43-
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
44-
-DCMAKE_FIND_ROOT_PATH=/usr/lib/riscv64-linux-gnu \
45-
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
46-
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
47-
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH
31+
# - name: Build
32+
# run: |
33+
# cmake -B build -DLLAMA_CURL=OFF \
34+
# -DCMAKE_BUILD_TYPE=Release \
35+
# -DGGML_OPENMP=OFF \
36+
# -DLLAMA_BUILD_EXAMPLES=ON \
37+
# -DLLAMA_BUILD_TOOLS=ON \
38+
# -DLLAMA_BUILD_TESTS=OFF \
39+
# -DCMAKE_SYSTEM_NAME=Linux \
40+
# -DCMAKE_SYSTEM_PROCESSOR=riscv64 \
41+
# -DCMAKE_C_COMPILER=riscv64-linux-gnu-gcc-14 \
42+
# -DCMAKE_CXX_COMPILER=riscv64-linux-gnu-g++-14 \
43+
# -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
44+
# -DCMAKE_FIND_ROOT_PATH=/usr/lib/riscv64-linux-gnu \
45+
# -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
46+
# -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
47+
# -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH
4848

49-
cmake --build build --config Release -j $(nproc)
49+
# cmake --build build --config Release -j $(nproc)
5050

5151
# ubuntu-24-riscv64-vulkan-cross:
5252
# runs-on: ubuntu-24.04

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ jobs:
134134
include:
135135
- build: 'x64'
136136
os: ubuntu-22.04
137-
- build: 's390x-z15' # z15 because our CI runners are on z15
138-
os: ubuntu-22.04-s390x
137+
- build: 's390x'
138+
os: ubuntu-24.04-s390x
139139
# GGML_BACKEND_DL and GGML_CPU_ALL_VARIANTS are not currently supported on arm
140140
# - build: 'arm64'
141141
# os: ubuntu-22.04-arm

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
/src/llama-model-loader.* @slaren
9090
/src/llama-model.* @CISC
9191
/src/llama-vocab.* @CISC
92+
/src/models/ @CISC
9293
/tests/ @ggerganov
9394
/tests/test-backend-ops.cpp @slaren
9495
/tests/test-thread-safety.cpp @slaren

common/arg.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
20302030
params.system_prompt.pop_back();
20312031
}
20322032
}
2033-
).set_examples({LLAMA_EXAMPLE_MAIN}));
2033+
).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_DIFFUSION}));
20342034
add_opt(common_arg(
20352035
{"--in-file"}, "FNAME",
20362036
"an input file (repeat to specify multiple files)",
@@ -2768,6 +2768,20 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
27682768
params.image.emplace_back(value);
27692769
}
27702770
).set_examples({LLAMA_EXAMPLE_MTMD}));
2771+
add_opt(common_arg(
2772+
{"--image-min-tokens"}, "N",
2773+
"minimum number of tokens each image can take, only used by vision models with dynamic resolution (default: read from model)",
2774+
[](common_params & params, int value) {
2775+
params.image_min_tokens = value;
2776+
}
2777+
).set_examples(mmproj_examples).set_env("LLAMA_ARG_IMAGE_MIN_TOKENS"));
2778+
add_opt(common_arg(
2779+
{"--image-max-tokens"}, "N",
2780+
"maximum number of tokens each image can take, only used by vision models with dynamic resolution (default: read from model)",
2781+
[](common_params & params, int value) {
2782+
params.image_max_tokens = value;
2783+
}
2784+
).set_examples(mmproj_examples).set_env("LLAMA_ARG_IMAGE_MAX_TOKENS"));
27712785
if (llama_supports_rpc()) {
27722786
add_opt(common_arg(
27732787
{"--rpc"}, "SERVERS",

common/chat.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ json common_chat_msgs_to_json_oaicompat(const std::vector<common_chat_msg> & msg
313313
}
314314
if (!msg.reasoning_content.empty()) {
315315
jmsg["reasoning_content"] = msg.reasoning_content;
316-
jmsg["thinking"] = msg.reasoning_content; // gpt-oss
317316
}
318317
if (!msg.tool_name.empty()) {
319318
jmsg["name"] = msg.tool_name;
@@ -1810,7 +1809,23 @@ static void common_chat_parse_deepseek_v3_1(common_chat_msg_parser & builder) {
18101809

18111810
static common_chat_params common_chat_params_init_gpt_oss(const common_chat_template & tmpl, const struct templates_params & inputs) {
18121811
common_chat_params data;
1813-
auto prompt = apply(tmpl, inputs);
1812+
1813+
// Copy reasoning to the "thinking" field as expected by the gpt-oss template
1814+
auto adjusted_messages = json::array();
1815+
for (const auto & msg : inputs.messages) {
1816+
auto has_reasoning_content = msg.contains("reasoning_content") && msg.at("reasoning_content").is_string();
1817+
auto has_tool_calls = msg.contains("tool_calls") && msg.at("tool_calls").is_array();
1818+
1819+
if (has_reasoning_content && has_tool_calls) {
1820+
auto adjusted_message = msg;
1821+
adjusted_message["thinking"] = msg.at("reasoning_content");
1822+
adjusted_messages.push_back(adjusted_message);
1823+
} else {
1824+
adjusted_messages.push_back(msg);
1825+
}
1826+
}
1827+
1828+
auto prompt = apply(tmpl, inputs, /* messages_override= */ adjusted_messages);
18141829

18151830
// Check if we need to replace the return token with end token during
18161831
// inference and without generation prompt. For more details see:

common/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ struct common_params {
406406
bool mmproj_use_gpu = true; // use GPU for multimodal model
407407
bool no_mmproj = false; // explicitly disable multimodal model
408408
std::vector<std::string> image; // path to image file(s)
409+
int image_min_tokens = -1;
410+
int image_max_tokens = -1;
409411

410412
// finetune
411413
struct lr_opt lr;

convert_hf_to_gguf.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9862,6 +9862,113 @@ def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iter
98629862

98639863
return [(self.map_tensor_name(name), data_torch)]
98649864

9865+
9866+
@ModelBase.register("JanusForConditionalGeneration")
9867+
class JanusProModel(LlamaModel):
9868+
model_arch = gguf.MODEL_ARCH.LLAMA # reuse Llama arch
9869+
9870+
def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iterable[tuple[str, Tensor]]:
9871+
# Skip vision, aligner, and generation tensors
9872+
skip_prefixes = (
9873+
'model.vision_model.',
9874+
'model.aligner.',
9875+
'model.vqmodel.',
9876+
'model.generation_embeddings.',
9877+
'model.generation_aligner.',
9878+
'model.generation_head.',
9879+
)
9880+
if name.startswith(skip_prefixes):
9881+
return []
9882+
9883+
if name.startswith('model.language_model.'):
9884+
name = name.replace('model.language_model.', 'model.')
9885+
elif name.startswith('language_model.'):
9886+
name = name.replace('language_model.', '')
9887+
9888+
return super().modify_tensors(data_torch, name, bid)
9889+
9890+
9891+
@ModelBase.register("JanusForConditionalGeneration")
9892+
class JanusProVisionModel(MmprojModel):
9893+
def __init__(self, *args, **kwargs):
9894+
super().__init__(*args, **kwargs)
9895+
assert self.hparams_vision is not None
9896+
if "intermediate_size" not in self.hparams_vision:
9897+
mlp_ratio = self.hparams_vision.get("mlp_ratio")
9898+
hidden_size = self.hparams_vision.get("hidden_size")
9899+
if mlp_ratio is not None and hidden_size is not None:
9900+
self.hparams_vision["intermediate_size"] = int(round(hidden_size * mlp_ratio))
9901+
9902+
def set_gguf_parameters(self):
9903+
super().set_gguf_parameters()
9904+
assert self.hparams_vision is not None
9905+
9906+
self.gguf_writer.add_clip_projector_type(gguf.VisionProjectorType.JANUS_PRO)
9907+
9908+
self.gguf_writer.add_vision_attention_layernorm_eps(self.hparams_vision.get("layer_norm_eps", 1e-6))
9909+
9910+
hidden_act = str(self.hparams_vision.get("hidden_act", "")).lower()
9911+
if hidden_act == "gelu":
9912+
self.gguf_writer.add_vision_use_gelu(True)
9913+
elif hidden_act == "silu":
9914+
self.gguf_writer.add_vision_use_silu(True)
9915+
9916+
def _map_aligner_tensor(self, data_torch: Tensor, name: str) -> Iterable[tuple[str, Tensor]]:
9917+
"""Map aligner tensors to projector format"""
9918+
suffix = ".bias" if name.endswith(".bias") else ".weight"
9919+
9920+
if name.startswith("model.aligner."):
9921+
local_name = name[len("model.aligner."):]
9922+
elif name.startswith("aligner."):
9923+
local_name = name[len("aligner."):]
9924+
else:
9925+
raise ValueError(f"Unsupported Janus aligner prefix: {name}")
9926+
9927+
if local_name.startswith("fc1."):
9928+
mm_index = 0
9929+
elif local_name.startswith("hidden_layers."):
9930+
parts = local_name.split(".", 2)
9931+
if len(parts) < 3:
9932+
raise ValueError(f"Unexpected Janus aligner tensor name: {name}")
9933+
mm_index = int(parts[1]) + 1
9934+
else:
9935+
raise ValueError(f"Unsupported Janus aligner tensor: {name}")
9936+
9937+
tensor_name = self.format_tensor_name(gguf.MODEL_TENSOR.V_MMPROJ, mm_index, suffix=suffix)
9938+
return [(tensor_name, data_torch)]
9939+
9940+
def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iterable[tuple[str, Tensor]]:
9941+
del bid # unused
9942+
9943+
# Skip language model tensors as they will be handled by `JanusProModel`
9944+
if name.startswith(('model.language_model.', 'language_model.')):
9945+
return []
9946+
9947+
# Skip generation-related components
9948+
skip_generation_prefixes = (
9949+
'model.vqmodel.',
9950+
'vqmodel.',
9951+
'model.generation_embeddings.',
9952+
'generation_embeddings.',
9953+
'model.generation_aligner.',
9954+
'generation_aligner.',
9955+
'model.generation_head.',
9956+
'generation_head.',
9957+
)
9958+
if name.startswith(skip_generation_prefixes):
9959+
return []
9960+
9961+
# Handle aligner tensors
9962+
if name.startswith(('model.aligner.', 'aligner.')):
9963+
return list(self._map_aligner_tensor(data_torch, name))
9964+
9965+
# Handle vision tensors
9966+
if name.startswith(('model.vision_model.', 'vision_model.')):
9967+
return [(self.map_tensor_name(name), data_torch)]
9968+
9969+
return []
9970+
9971+
98659972
###### CONVERSION LOGIC ######
98669973

98679974

docs/docker.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
## Images
88
We have three Docker images available for this project:
99

10-
1. `ghcr.io/ggml-org/llama.cpp:full`: This image includes both the main executable file and the tools to convert LLaMA models into ggml and convert into 4-bit quantization. (platforms: `linux/amd64`, `linux/arm64`)
11-
2. `ghcr.io/ggml-org/llama.cpp:light`: This image only includes the main executable file. (platforms: `linux/amd64`, `linux/arm64`)
12-
3. `ghcr.io/ggml-org/llama.cpp:server`: This image only includes the server executable file. (platforms: `linux/amd64`, `linux/arm64`)
10+
1. `ghcr.io/ggml-org/llama.cpp:full`: This image includes both the main executable file and the tools to convert LLaMA models into ggml and convert into 4-bit quantization. (platforms: `linux/amd64`, `linux/arm64`, `linux/s390x`)
11+
2. `ghcr.io/ggml-org/llama.cpp:light`: This image only includes the main executable file. (platforms: `linux/amd64`, `linux/arm64`, `linux/s390x`)
12+
3. `ghcr.io/ggml-org/llama.cpp:server`: This image only includes the server executable file. (platforms: `linux/amd64`, `linux/arm64`, `linux/s390x`)
1313

1414
Additionally, there the following images, similar to the above:
1515

examples/model-conversion/scripts/causal/run-org-model.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ def fn(_m, input, output):
138138
"Model path must be specified either via --model-path argument or MODEL_PATH environment variable"
139139
)
140140

141+
142+
print("Loading model and tokenizer using AutoTokenizer:", model_path)
143+
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
141144
config = AutoConfig.from_pretrained(model_path, trust_remote_code=True)
142145

143146
print("Model type: ", config.model_type)
@@ -147,10 +150,6 @@ def fn(_m, input, output):
147150
print("BOS token id: ", config.bos_token_id)
148151
print("EOS token id: ", config.eos_token_id)
149152

150-
print("Loading model and tokenizer using AutoTokenizer:", model_path)
151-
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
152-
config = AutoConfig.from_pretrained(model_path, trust_remote_code=True)
153-
154153
if unreleased_model_name:
155154
model_name_lower = unreleased_model_name.lower()
156155
unreleased_module_path = (
@@ -171,7 +170,7 @@ def fn(_m, input, output):
171170
exit(1)
172171
else:
173172
model = AutoModelForCausalLM.from_pretrained(
174-
model_path, device_map="auto", offload_folder="offload", trust_remote_code=True
173+
model_path, device_map="auto", offload_folder="offload", trust_remote_code=True, config=config
175174
)
176175

177176
for name, module in model.named_modules():

0 commit comments

Comments
 (0)