DeepHermes-3-Llama-3-8B-Preview:统一推理与常规响应模式,支持函数调用与长思维链的智能语言模型

DeepHermes 3 Preview是Nous Research推出的旗舰LLM,全球首批统一推理(长思维链提升准确率)与常规响应模式的模型,支持函数调用、角色扮演和多轮对话,用户可通过系统提示切换模式。【此简介由AI生成】

分支1Tags0
ea208822创建于 2025年4月11日7次提交
文件最后提交记录最后更新时间
Update README.md (#2) - Update README.md (c1fa39d45bf16e63e4efd1f2c08b2eb90a5bfcd2) Co-authored-by: Michael Coppola <m18coppola@users.noreply.huggingface.co> 1 年前
Update README.md 1 年前
Update config.json (#8) - Update config.json (7832131994511052c0b732472cf3e76ae75d036b) Co-authored-by: Joseph <Joseph717171@users.noreply.huggingface.co> 1 年前
Update README.md 1 年前
Update README.md 1 年前
Update README.md 1 年前
Update README.md 1 年前
Update README.md 1 年前
Update README.md 1 年前
Update README.md 1 年前
Update README.md 1 年前
Update README.md 1 年前
Update README.md 1 年前

language:

  • en license: llama3 tags:
  • Llama-3
  • instruct
  • finetune
  • chatml
  • gpt4
  • synthetic data
  • distillation
  • function calling
  • json mode
  • axolotl
  • roleplaying
  • chat
  • reasoning
  • r1
  • vllm base_model: meta-llama/Meta-Llama-3.1-8B widget:
  • example_title: Hermes 3 messages:
    • role: system content: >- You are a sentient, superintelligent artificial general intelligence, here to teach and assist me.
    • role: user content: What is the meaning of life? model-index:
  • name: DeepHermes-3-Llama-3.1-8B results: [] library_name: transformers

DeepHermes 3 - Llama-3.1 8B

image/jpeg

模型简介

DeepHermes 3 Preview 是我们 Nous Research 旗舰系列 Hermes 大语言模型的最新版本,也是全球首批将推理(提升答案准确性的长链思维)与常规大语言模型响应模式融于一体的大模型之一。我们还改进了大语言模型的标注、判断与函数调用能力。

DeepHermes 3 Preview 是业界首个将"直觉式"传统响应模式与长链思维推理响应模式集成于单一模型的先驱之作,仅需通过系统提示词即可切换模式。

作为 DeepHermes 3 的前代产品,Hermes 3 是一款全能型语言模型,相比 Hermes 2 实现了全面升级:增强了智能体能力,显著提升了角色扮演、推理、多轮对话和长上下文连贯性等核心性能。

Hermes 系列模型始终秉持"以用户为中心"的设计理念,致力于为用户提供强大的引导能力和终端控制权。

当前版本为具备早期推理能力的预览版,其能力源自 R1 模型在多种受益于推理与客观性任务上的蒸馏成果。您可能会发现某些特殊现象!欢迎随时向我们反馈有趣的发现或问题!

重要提示:若要启用推理模式,必须使用以下系统提示词:

You are a deep thinking AI, you may use extremely long chains of thought to deeply consider the problem and deliberate with yourself via systematic reasoning processes to help come to a correct solution prior to answering. You should enclose your thoughts and internal monologue inside <think> </think> tags, and then provide your solution or response to the problem.

Nous API

该模型现已登陆我们的全新API产品——欢迎查看API详情并在此处注册加入等候列表: https://portal.nousresearch.com/

示例输出:

image/png

image/png

image/png

image/png

基准测试

推理模式开启与关闭的基准对比:

image/png

开启推理模式的基准数据通过运行HuggingFace的open-r1推理模式评估套件获得,关闭推理模式的分数通过LM-Eval-Harness基准测试套件测得 上限值通过MATH_VERIFY对比Hermes 3 3B和70B版本的增益百分比确定,与eleuther评估框架相比,在重新测试的模型上MATH Hard基准测试中增益幅度介于33%至50%之间

非推理模式下与Llama-3.1-8B-Instruct的基准对比

image/png

提示词格式

DeepHermes 3现采用Llama-Chat格式作为提示词模板,为多轮对话交互提供了更统一、结构化的系统框架。

系统提示词可实现导向控制,提供与大型语言模型交互的新颖方式,引导模型遵循规则、角色设定和风格选择。

深度思考模式 - Deep Hermes预览版可通过系统提示词激活长链推理思维。

You are a deep thinking AI, you may use extremely long chains of thought to deeply consider the problem and deliberate with yourself via systematic reasoning processes to help come to a correct solution prior to answering. You should enclose your thoughts and internal monologue inside <think> </think> tags, and then provide your solution or response to the problem.

以下是使用HuggingFace Transformers进行深度推理模式的示例:

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
import flash_attn
import time

tokenizer = AutoTokenizer.from_pretrained("NousResearch/DeepHermes-3-Llama-3-8B-Preview")

model = AutoModelForCausalLM.from_pretrained(
    "NousResearch/DeepHermes-3-Llama-3-8B-Preview",
    torch_dtype=torch.float16,
    device_map="auto",
    attn_implementation="flash_attention_2",
)

messages = [
    {
        "role": "system",
        "content": "You are a deep thinking AI, you may use extremely long chains of thought to deeply consider the problem and deliberate with yourself via systematic reasoning processes to help come to a correct solution prior to answering. You should enclose your thoughts and internal monologue inside <think> </think> tags, and then provide your solution or response to the problem."
    },
    {
        "role": "user",
        "content": "What is y if y=2*2-4+(3*2)"
    }
]

input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors='pt').to("cuda")
generated_ids = model.generate(input_ids, max_new_tokens=2500, temperature=0.8, repetition_penalty=1.1, do_sample=True, eos_token_id=tokenizer.eos_token_id)
print(f"Generated Tokens: {generated_ids.shape[-1:]}")
response = tokenizer.decode(generated_ids[0], skip_special_tokens=True, clean_up_tokenization_space=True)
print(f"Response: {response}")

请注意,对于复杂问题,DeepHermes 可能会使用多达 13,000 个令牌进行思考。对于难题,您可能需要将 max_new_tokens 增加到远大于 2500 的值。

标准「直觉式」响应模式

附带系统指令的提示(您可以使用任意系统提示,以下仅为示例!):

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
import flash_attn
import time

tokenizer = AutoTokenizer.from_pretrained("NousResearch/DeepHermes-3-Llama-3-8B-Preview")

model = AutoModelForCausalLM.from_pretrained(
    "NousResearch/DeepHermes-3-Llama-3-8B-Preview",
    torch_dtype=torch.float16,
    device_map="auto",
    attn_implementation="flash_attention_2",
)

messages = [
    {
        "role": "system",
        "content": "You are Hermes, an AI assistant"
    },
    {
        "role": "user",
        "content": "What are the most interesting things to do in Paris?"
    }
]

input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors='pt').to("cuda")
generated_ids = model.generate(input_ids, max_new_tokens=2500, temperature=0.8, repetition_penalty=1.1, do_sample=True, eos_token_id=tokenizer.eos_token_id)
print(f"Generated Tokens: {generated_ids.shape[-1:]}")
response = tokenizer.decode(generated_ids[0], skip_special_tokens=True, clean_up_tokenization_space=True)
print(f"Response: {response}")

VLLM 推理部署

您也可以通过 vLLM 运行此模型,只需在终端中执行 pip install vllm 后运行以下命令:

vllm serve NousResearch/DeepHermes-3-Llama-3-8B-Preview

随后即可像调用 OpenAI API 一样,通过 OpenAI 库以 API 形式使用该模型。

函数调用提示词格式

本模型针对函数调用功能采用了特定的系统提示词结构和训练方案。

请按照以下示例方式,先使用系统角色发送指定消息,随后附上函数签名的 JSON 结构。

<|start_header_id|>system<|end_header_id|>
You are a function calling AI model. You are provided with function signatures within <tools></tools> XML tags. You may call one or more functions to assist with the user query. Don't make assumptions about what values to plug into functions. Here are the available tools: <tools> {"type": "function", "function": {"name": "get_stock_fundamentals", "description": "get_stock_fundamentals(symbol: str) -> dict - Get fundamental data for a given stock symbol using yfinance API.\\n\\n    Args:\\n        symbol (str): The stock symbol.\\n\\n    Returns:\\n        dict: A dictionary containing fundamental data.\\n            Keys:\\n                - \'symbol\': The stock symbol.\\n                - \'company_name\': The long name of the company.\\n                - \'sector\': The sector to which the company belongs.\\n                - \'industry\': The industry to which the company belongs.\\n                - \'market_cap\': The market capitalization of the company.\\n                - \'pe_ratio\': The forward price-to-earnings ratio.\\n                - \'pb_ratio\': The price-to-book ratio.\\n                - \'dividend_yield\': The dividend yield.\\n                - \'eps\': The trailing earnings per share.\\n                - \'beta\': The beta value of the stock.\\n                - \'52_week_high\': The 52-week high price of the stock.\\n                - \'52_week_low\': The 52-week low price of the stock.", "parameters": {"type": "object", "properties": {"symbol": {"type": "string"}}, "required": ["symbol"]}}}  </tools> Use the following pydantic model json schema for each tool call you will make: {"properties": {"arguments": {"title": "Arguments", "type": "object"}, "name": {"title": "Name", "type": "string"}}, "required": ["arguments", "name"], "title": "FunctionCall", "type": "object"} For each function call return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows:
<tool_call>
{"arguments": <args-dict>, "name": <function-name>}
</tool_call><|eot_id|><|start_header_id|>user<|end_header_id|>

要完成函数调用,请按照上述系统提示创建一个用户提示,如下所示:

Fetch the stock fundamentals data for Tesla (TSLA)<|eot_id|><|start_header_id|>assistant<|end_header_id|>

随后,模型将生成一个工具调用,您的推理代码必须解析该调用并将其插入到一个函数中(参见示例推理代码:https://github.com/NousResearch/Hermes-Function-Calling):

<tool_call>
{"arguments": {"symbol": "TSLA"}, "name": "get_stock_fundamentals"}
</tool_call><|eot_id|><|start_header_id|>tool<|end_header_id|>

一旦解析完工具调用,调用API并获取该调用的返回值,然后以新角色tool的形式将其传回,如下所示:

<tool_response>
{"name": "get_stock_fundamentals", "content": {'symbol': 'TSLA', 'company_name': 'Tesla, Inc.', 'sector': 'Consumer Cyclical', 'industry': 'Auto Manufacturers', 'market_cap': 611384164352, 'pe_ratio': 49.604652, 'pb_ratio': 9.762013, 'dividend_yield': None, 'eps': 4.3, 'beta': 2.427, '52_week_high': 299.29, '52_week_low': 152.37}}
</tool_response>
<|eot_id|><|start_header_id|>assistant<|end_header_id|>

助手随后将从函数响应中读取该数据,并生成自然语言回复:

The stock fundamentals data for Tesla (TSLA) are as follows:
- **Symbol**: TSLA
- **Company Name**: Tesla, Inc.
- **Sector**: Consumer Cyclical
- **Industry**: Auto Manufacturers
- **Market Capitalization**: $566,160,130,480
- **Forward Price-to-Earnings Ratio (PE Ratio)**: 42.73
- **Price-to-Book Ratio (PB Ratio)**: 9.04
- **Dividend Yield**: N/A
- **Trailing Earnings Per Share (EPS)**: $4.3
- **Beta Value of the Stock**: 2.42
- **52-Week High Price of the Stock**: $299.29
- **52-Week Low Price of the Stock**: $152.37

This information provides a snapshot of Tesla's financial position and performance based on the fundamental data obtained from the yfinance API. It shows that Tesla has a substantial market capitalization and a relatively high P/E and P/B ratio compared to other stocks in its industry. The company does not pay a dividend at the moment, which is reflected by a 'Dividend Yield' of 'None'. The Beta value indicates that Tesla's stock has a moderate level of volatility relative to the market. The 52-week high and low prices give an idea of the stock's range over the past year. This data can be useful when assessing investment opportunities and making investment decisions.<|eot_id|><|start_header_id|>user<|end_header_id|>

JSON 模式/结构化输出的提示格式

我们的模型还针对结构化输出进行了特定系统提示的训练,该模式下应返回符合特定 JSON 架构的 JSON 对象响应。

您可以通过我们的代码库使用 Pydantic 对象构建架构,具体可参考此处提供的独立脚本 jsonmode.pyhttps://github.com/NousResearch/Hermes-Function-Calling/tree/main

<|start_header_id|>system<|end_header_id|>
You are a helpful assistant that answers in JSON. Here's the json schema you must adhere to:\n<schema>\n{schema}\n</schema><|eot_id|>

根据您提供的 {schema},响应内容应遵循该 JSON 格式进行构建。您只需输入典型的用户提示,系统即会以 JSON 格式作出回应。

函数调用推理代码:

所有关于使用、解析和构建函数调用模板的代码均已开源至我们的 GitHub: https://github.com/NousResearch/Hermes-Function-Calling

image/png

量化版本:

GGUF 量化版本:https://huggingface.co/NousResearch/DeepHermes-3-Llama-3-8B-Preview-GGUF

引用方式:

@misc{
      title={DeepHermes 3 Preview}, 
      author={Teknium and Roger Jin and Chen Guang and Jai Suphavadeeprasit and Jeffrey Quesnelle},
      year={2025}
}

项目介绍

DeepHermes 3 Preview是Nous Research推出的旗舰LLM,全球首批统一推理(长思维链提升准确率)与常规响应模式的模型,支持函数调用、角色扮演和多轮对话,用户可通过系统提示切换模式。【此简介由AI生成】

定制我的领域

下载使用量

0

项目总下载次数(含Clone、Pull、 zip 包及 release 下载),每日凌晨更新