🚀 Codestral-22B-v0.1模型卡片
Codestrall-22B-v0.1在包含80多種編程語言的多樣化數據集上進行訓練,涵蓋了Python、Java、C、C++、JavaScript和Bash等最流行的語言(更多詳細信息請參閱博客文章)。該模型可以通過以下方式進行查詢:
- 指令式查詢,例如回答關於代碼片段的任何問題(編寫文檔、解釋代碼、代碼重構)或根據特定指示生成代碼。
- 中間填充(FIM),用於預測前綴和後綴之間的中間標記(這對於VS Code等軟件開發插件非常有用)。
🚀 快速開始
2024年5月31日更新:修復了原模型更新後的分詞器問題:https://huggingface.co/mistralai/Codestral-22B-v0.1/discussions/10
使用此腳本進行轉換。
✨ 主要特性
- 支持80多種編程語言,能處理多種編程相關任務。
- 提供指令式查詢和中間填充(FIM)兩種查詢方式。
📦 安裝指南
建議將mistralai/Codestral-22B-v0.1
與mistral-inference一起使用。
pip install mistral_inference
下載模型
from huggingface_hub import snapshot_download
from pathlib import Path
mistral_models_path = Path.home().joinpath('mistral_models', 'Codestral-22B-v0.1')
mistral_models_path.mkdir(parents=True, exist_ok=True)
snapshot_download(repo_id="mistralai/Codestral-22B-v0.1", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], local_dir=mistral_models_path)
💻 使用示例
基礎用法
聊天功能
安裝mistral_inference
後,環境中會有mistral-chat
命令行工具。
mistral-chat $HOME/mistral_models/Codestral-22B-v0.1 --instruct --max_tokens 256
該命令會對“用Rust編寫一個計算斐波那契數列的函數”這一問題生成答案,可能如下:
Sure, here's a simple implementation of a function that computes the Fibonacci sequence in Rust. This function takes an integer `n` as an argument and returns the `n`th Fibonacci number.
fn fibonacci(n: u32) -> u32 {
match n {
0 => 0,
1 => 1,
_ => fibonacci(n - 1) + fibonacci(n - 2),
}
}
fn main() {
let n = 10;
println!("The {}th Fibonacci number is: {}", n, fibonacci(n));
}
This function uses recursion to calculate the Fibonacci number. However, it's not the most efficient solution because it performs a lot of redundant calculations. A more efficient solution would use a loop to iteratively calculate the Fibonacci numbers.
中間填充(FIM)功能
安裝mistral_inference
並運行pip install --upgrade mistral_common
以確保安裝了mistral_common>=1.2
:
from mistral_inference.model import Transformer
from mistral_inference.generate import generate
from mistral_common.tokens.tokenizers.mistral import MistralTokenizer
from mistral_common.tokens.instruct.request import FIMRequest
tokenizer = MistralTokenizer.v3()
model = Transformer.from_folder("~/codestral-22B-240529")
prefix = """def add("""
suffix = """ return sum"""
request = FIMRequest(prompt=prefix, suffix=suffix)
tokens = tokenizer.encode_fim(request).tokens
out_tokens, _ = generate([tokens], model, max_tokens=256, temperature=0.0, eos_id=tokenizer.instruct_tokenizer.tokenizer.eos_id)
result = tokenizer.decode(out_tokens[0])
middle = result.split(suffix)[0].strip()
print(middle)
該代碼可能會輸出如下內容:
num1, num2):
# Add two numbers
sum = num1 + num2
# return the sum
📚 詳細文檔
侷限性
Codestral-22B-v0.1沒有任何審核機制。我們期待與社區共同探討如何讓模型更好地遵守規則,以便在需要審核輸出的環境中進行部署。
📄 許可證
Codestral-22B-v0.1採用MNLP-0.1
許可證發佈。
🔧 技術細節
該模型由Mistral AI團隊開發,團隊成員包括Albert Jiang、Alexandre Sablayrolles、Alexis Tacnet等眾多人員。模型在80多種編程語言的多樣化數據集上進行訓練,可通過指令式和中間填充(FIM)兩種方式進行查詢。
信息表格
屬性 |
詳情 |
模型類型 |
Codestral-22B-v0.1 |
訓練數據 |
80多種編程語言的多樣化數據集 |
許可證 |
MNLP-0.1 |