🚀 Cogito v1 preview - 32B
Cogitoの大規模言語モデル(LLM)は、命令に基づいてテキストを生成するモデルです。全てのモデルは商用利用可能なオープンライセンスで公開されています。
ブログ記事
🚀 クイックスタート
CogitoのLLMは、命令に基づいて生成するモデル(テキスト入力/テキスト出力)です。全てのモデルは商用利用可能なオープンライセンスで公開されています。
- Cogitoモデルはハイブリッド推論モデルです。各モデルは直接回答することも(標準的なLLMのように)、回答前に自己反省することもできます(推論モデルのように)。
- LLMはIterated Distillation and Amplification (IDA) を使用して学習されています。これは、反復的な自己改善を用いた、超知能のためのスケーラブルで効率的なアライメント戦略です。
- モデルはコーディング、STEM、命令の実行、および一般的な有用性に関して最適化されており、同等のサイズのモデルと比較して、多言語、コーディング、およびツール呼び出し能力が大幅に向上しています。
- 標準モードと推論モードの両方で、Cogito v1-previewモデルは一般的な業界ベンチマークで同等のサイズのモデルを上回っています。
- 各モデルは30以上の言語で学習されており、128kのコンテキスト長をサポートしています。
✨ 主な機能
評価
我々は、モデルを標準モードおよび推論モードで、最先端の同等サイズのモデルと比較しています。標準モードでは、Llama / Qwenの命令対応モデルと比較しています。推論モードでは、DeepseekのR1蒸留モデル / QwenのQwQモデルを使用しています。
Livebenchグローバル平均:
詳細な評価については、ブログ記事 を参照してください。
💻 使用例
基本的な使用法
以下は、Transformersを使用した使用例です。
import transformers
import torch
model_id = "deepcogito/cogito-v1-preview-qwen-32B"
pipeline = transformers.pipeline(
"text-generation",
model=model_id,
model_kwargs={"torch_dtype": torch.bfloat16},
device_map="auto",
)
messages = [
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
{"role": "user", "content": "Give me a short introduction to LLMs."},
]
outputs = pipeline(
messages,
max_new_tokens=512,
)
print(outputs[0]["generated_text"][-1])
高度な使用法
拡張思考の実装
- デフォルトでは、モデルは標準モードで回答します。
- 思考を有効にするには、以下の2つの方法のいずれかを行うことができます。
- 特定のシステムプロンプトを追加する、または
- チャットテンプレートを適用する際に
enable_thinking=True
を設定する。
方法1 - 特定のシステムプロンプトを追加する
思考を有効にするには、システムプロンプトで system_instruction = 'Enable deep thinking subroutine.'
を使用します。
既にシステム命令がある場合は、system_instruction = 'Enable deep thinking subroutine.' + '\n\n' + system_instruction
を使用します。
以下は例です。
import transformers
import torch
model_id = "deepcogito/cogito-v1-preview-qwen-32B"
pipeline = transformers.pipeline(
"text-generation",
model=model_id,
model_kwargs={"torch_dtype": torch.bfloat16},
device_map="auto",
)
DEEP_THINKING_INSTRUCTION = "Enable deep thinking subroutine."
messages = [
{"role": "system", "content": DEEP_THINKING_INSTRUCTION},
{"role": "user", "content": "Write a bash script that takes a matrix represented as a string with format '[1,2],[3,4],[5,6]' and prints the transpose in the same format."},
]
outputs = pipeline(
messages,
max_new_tokens=512,
)
print(outputs[0]["generated_text"][-1])
同様に、システムプロンプトがある場合は、DEEP_THINKING_INSTRUCTION
を以下のように先頭に追加することができます。
DEEP_THINKING_INSTRUCTION = "Enable deep thinking subroutine."
system_prompt = "Reply to each prompt with only the actual code - no explanations."
prompt = "Write a bash script that takes a matrix represented as a string with format '[1,2],[3,4],[5,6]' and prints the transpose in the same format."
messages = [
{"role": "system", "content": DEEP_THINKING_INSTRUCTION + '\n\n' + system_prompt},
{"role": "user", "content": prompt}
]
方法2 - トークナイザで enable_thinking=True
を設定する
Huggingfaceのトークナイザを使用している場合は、トークナイゼーションに enable_thinking=True
引数を追加するだけです(このオプションはチャットテンプレートに追加されています)。
以下は例です。
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "deepcogito/cogito-v1-preview-qwen-32B"
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
prompt = "Give me a short introduction to LLMs."
messages = [
{"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
enable_thinking=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(
**model_inputs,
max_new_tokens=512
)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)
ツール呼び出し
Cogitoモデルは、標準モードと拡張思考モードの両方で、ツール呼び出し(単一、並列、複数、および並列複数)をサポートしています。
以下はスニペットです。
def get_current_temperature(location: str) -> float:
"""
Get the current temperature at a location.
Args:
location: The location to get the temperature for, in the format "City, Country"
Returns:
The current temperature at the specified location in the specified units, as a float.
"""
return 22.
messages = [
{"role": "user", "content": "Hey, what's the temperature in Paris right now?"}
]
model_inputs = tokenizer.apply_chat_template(messages, tools=[get_current_temperature], add_generation_prompt=True)
text = tokenizer.apply_chat_template(messages, tools=[get_current_temperature], add_generation_prompt=True, tokenize=False)
inputs = tokenizer(text, return_tensors="pt", add_special_tokens=False).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512)
output_text = tokenizer.batch_decode(outputs)[0][len(text):]
print(output_text)
これにより、以下の出力が得られます。
<tool_call>
{"name": "get_current_temperature", "arguments": {"location": "Paris, France"}}
</tool_call><|im_end|>
この入力から通常通りテキストを生成することができます。モデルがツール呼び出しを生成した場合は、以下のようにチャットに追加する必要があります。
tool_call = {"name": "get_current_temperature", "arguments": {"location": "Paris, France"}}
messages.append({"role": "assistant", "tool_calls": [{"type": "function", "function": tool_call}]})
そして、ツールを呼び出し、結果を tool
ロールで追加します。
messages.append({"role": "tool", "name": "get_current_temperature", "content": "22.0"})
その後、再度 generate()
を呼び出すことで、モデルがチャットでツールの結果を使用することができます。
text = tokenizer.apply_chat_template(messages, tools=[get_current_temperature], add_generation_prompt=True, tokenize=False)
inputs = tokenizer(text, return_tensors="pt", add_special_tokens=False).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512)
output_text = tokenizer.batch_decode(outputs)[0][len(text):]
これにより、以下の文字列が得られるはずです。
'The current temperature in Paris is 22.0 degrees.<|im_end|>'
📄 ライセンス
このリポジトリとモデルの重みは、Apache 2.0ライセンス契約の下でライセンスされています。
📞 お問い合わせ
当チームに連絡したい場合は、contact@deepcogito.com までメールを送信してください。