How to use "Gemma-4-E4B-it-heretic-GGUF" ?

未关闭
#2,175 3 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
python
领域
ai, devtools

调研方向

这个 issue 涉及特定 GGUF 文件导致的模型行为不正确。首先查看 llama-cpp-python 关于 chat_format 参数和 Llama 构造函数的文档。运行提供的代码以复现问题,然后与 repository 示例中的已知可用配置进行比较。查找关于 'gemma-4' chat format 或模型加载的现有 issues。

由索引模型根据 Issue 内容生成。

描述

Hi I'm currently tried every models possible from Qwen3.5-9B-Claude-4.6-Opus-abliterated to c4ai-command-r7b but since the Gemma-4-E4B just released, I found it interesting and I want do some research with it but I couldn't get it to work the way I want it to. When I ask it to translate stuffs or asking to help about any project, it would just spamming stuffs or just analyze feelings, explaining nonsenses. Unlike via Koboldcpp, it worked smoothly and could answering me correctly but I want to use it on python only not Koboldcpp. Any assistant would be appreciated ! Below is my code

import os
import gc
import asyncio
from concurrent.futures import ThreadPoolExecutor
from llama_cpp import Llama
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file)))
MODEL_PATH = os.path.join(BASE_DIR, "models", "gemma-4-E4B-it-heretic-Q4_K_M.gguf")
conversation_history = []
print("Loading!")
try:
llm = Llama(
model_path=MODEL_PATH,
n_gpu_layers=-1,
n_ctx=6144,
verbose=True,
use_mlock=True,
use_mmap=True,
n_batch=2048,
n_ubatch=1024,
offload_kqv=True,
last_n_tokens_size=128,
mul_mat_q=True,
chat_format="gemma-4",
stop=["<|turn|>"],
cuda_graphs=True,
n_threads=os.cpu_count() or 8,
n_threads_batch=os.cpu_count() or 8,
)
print("Loaded!")
except Exception as e:
print(f"Failed! {e}")
llm = None
def local_ai(text):
global conversation_history
if not llm:
return "Cannt be loaded", None
try:
messages = [
{
"role": "system",
"content": "You're a brillant assistant AI! Provide what in needs!"
}
]
if len(conversation_history) > 4:
conversation_history = conversation_history[-4:]
messages.extend(conversation_history)
messages.append({"role": "user", "content": {text}"})
response = llm.create_chat_completion(
messages=messages,
max_tokens=1024,
temperature=0.1,
top_p=0.9,
top_k=40,
repeat_penalty=1.1,
)
output = response['choices'][0]['message']['content'].strip()
conversation_history.append({"role": "user", "content": {text}"})
conversation_history.append({"role": "assistant", "content": output})
gc.collect()
return output
except Exception as e:
print(f"CRITICAL: {e}")
return "GONE WRONG!", None
async def async(text):
loop = asyncio.get_event_loop()
try:
return await loop.run_in_executor(executor, local_ai, text, lang)
except Exception as e:
print(f"Async Error: {e}")
return None, None

主要语言
Python
星标
10.7k
派生
1.5k
平均合并
1 小时 40 分钟
30 天内合并 PR
5

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

abetlen/llama-cpp-python 的其他 Issue

查看 abetlen/llama-cpp-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。