Views
No views yet
mistralai/Mistral-7B-Instruct-v0.3 at load time.kernels/MistralRMSNorm and kernels/MistralMLP ship as precompiled .so binaries only — the CUDA source (kernel.cu) is not included in this release. They will only load on a matching stack:cp312)pip install will succeed but importing the extension will fail or crash. If you need a different environment, you'll need to rebuild from source — source is not currently published here.pip install -r requirements.txt1pip install kernels/MistralRMSNorm
2pip install kernels/MistralMLPmodeling_mistral.py (MistralRMSNorm.forward and MistralMLP.forward only, verified by diff against the upstream release). Install upstream transformers at that version, then drop in the patched file from patched_transformers/:1pip install transformers==5.8.1
2python -c "import transformers, os, shutil; d = os.path.dirname(transformers.__file__) + '/models/mistral'; shutil.copy('patched_transformers/modeling_mistral.py', d)"1# Install wheel support
2pip install wheel
3
4# Install flash-attn from prebuilt wheel
5pip install https://github.com/mjun0812/flash-attention-prebuild-wheels/releases/download/v0.9.4/flash_attn-2.8.3+cu130torch2.11-cp312-cp312-linux_x86_64.whl
6
7# Verify
8python -c "import flash_attn; print('flash-attn OK, version:', flash_attn.__version__)"transformers library — the CUDA kernels are injected transparently. Mistral-7B-Instruct is a chat-tuned model, so use apply_chat_template rather than passing raw text:1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3")
4tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3")
5
6messages = [{"role": "user", "content": "Hello, how are you?"}]
7inputs = tokenizer.apply_chat_template(
8 messages, add_generation_prompt=True, return_tensors="pt"
9).to("cuda")
10model = model.cuda()
11outputs = model.generate(inputs, max_new_tokens=200)
12print(tokenizer.decode(outputs[0], skip_special_tokens=True))transformers serve:transformers serve --model mistralai/Mistral-7B-Instruct-v0.3 --port 8000| Metric | Baseline | Optimized | Delta |
|---|---|---|---|
| Inference throughput (tok/s) | 51.51 | 67.38 | +30.8% |
| GSM8K accuracy (50-sample) | 0.46 | 0.38 | -0.08 (within statistical variance) |
| Training throughput (tok/s) | 4,787.9 | 8,263.8 | +72.6% (1.73x) |
position_embeddings API needed for autoregressive generation, so standard FlashAttention-2 is used instead.backward() does not return weight gradients (it's an inference-optimized kernel). During full finetuning, MLP projection weights stay frozen while attention weights train normally — disable the MLP kernel if you need to finetune MLP weights.patched_transformers/ contains targeted modifications only to MistralRMSNorm.forward and MistralMLP.forward, based on transformers v5.8.1. modular_mistral.py is unmodified from upstream and is not included here.