Text Generation
Transformers
PyTorch
Safetensors
GGUF
Norwegian
Norwegian Bokmål
Norwegian Nynorsk
mistral
gpt
generative
text-generation-inference
Instructions to use norallm/normistral-7b-scratch with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use norallm/normistral-7b-scratch with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="norallm/normistral-7b-scratch")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("norallm/normistral-7b-scratch") model = AutoModelForCausalLM.from_pretrained("norallm/normistral-7b-scratch", device_map="auto") - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use norallm/normistral-7b-scratch with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf norallm/normistral-7b-scratch:Q4_K_M # Run inference directly in the terminal: llama cli -hf norallm/normistral-7b-scratch:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf norallm/normistral-7b-scratch:Q4_K_M # Run inference directly in the terminal: llama cli -hf norallm/normistral-7b-scratch:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf norallm/normistral-7b-scratch:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf norallm/normistral-7b-scratch:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf norallm/normistral-7b-scratch:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf norallm/normistral-7b-scratch:Q4_K_M
Use Docker
docker model run hf.co/norallm/normistral-7b-scratch:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use norallm/normistral-7b-scratch with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "norallm/normistral-7b-scratch" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "norallm/normistral-7b-scratch", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/norallm/normistral-7b-scratch:Q4_K_M
- SGLang
How to use norallm/normistral-7b-scratch with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "norallm/normistral-7b-scratch" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "norallm/normistral-7b-scratch", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "norallm/normistral-7b-scratch" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "norallm/normistral-7b-scratch", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Ollama
How to use norallm/normistral-7b-scratch with Ollama:
ollama run hf.co/norallm/normistral-7b-scratch:Q4_K_M
- Unsloth Studio
How to use norallm/normistral-7b-scratch with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for norallm/normistral-7b-scratch to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for norallm/normistral-7b-scratch to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for norallm/normistral-7b-scratch to start chatting
- Docker Model Runner
How to use norallm/normistral-7b-scratch with Docker Model Runner:
docker model run hf.co/norallm/normistral-7b-scratch:Q4_K_M
- Lemonade
How to use norallm/normistral-7b-scratch with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull norallm/normistral-7b-scratch:Q4_K_M
Run and chat with the model
lemonade run user.normistral-7b-scratch-Q4_K_M
List all available models
lemonade list
- Atomic Chat
Upload folder using huggingface_hub
Browse files- config.json +24 -0
- convert_weight.py +81 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +1 -0
- tokenizer.json +0 -0
- tokenizer_config.json +2 -0
config.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"MistralForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"bos_token_id": 1,
|
| 6 |
+
"eos_token_id": 2,
|
| 7 |
+
"hidden_act": "silu",
|
| 8 |
+
"hidden_size": 4096,
|
| 9 |
+
"initializer_range": 0.02,
|
| 10 |
+
"intermediate_size": 14336,
|
| 11 |
+
"max_position_embeddings": 2048,
|
| 12 |
+
"model_type": "mistral",
|
| 13 |
+
"num_attention_heads": 32,
|
| 14 |
+
"num_hidden_layers": 32,
|
| 15 |
+
"num_key_value_heads": 8,
|
| 16 |
+
"rms_norm_eps": 1e-05,
|
| 17 |
+
"rope_theta": 10000.0,
|
| 18 |
+
"sliding_window": 2048,
|
| 19 |
+
"tie_word_embeddings": false,
|
| 20 |
+
"torch_dtype": "bfloat16",
|
| 21 |
+
"transformers_version": "4.34.0.dev0",
|
| 22 |
+
"use_cache": true,
|
| 23 |
+
"vocab_size": 32768
|
| 24 |
+
}
|
convert_weight.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from tqdm import tqdm
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
input_dir_path = "/scratch/project_462000086/norwegian_gpt/Megatron-DeepSpeed-fixed/mistral-7b-from-scratch-2nd-run/global_step30000"
|
| 6 |
+
output_dir_path = "/scratch/project_462000086/norwegian_gpt/Megatron-DeepSpeed-fixed/hf_mistral_from_scratch_60k"
|
| 7 |
+
|
| 8 |
+
n_hidden = 4096
|
| 9 |
+
n_ffn_hidden = 14336
|
| 10 |
+
n_heads = 32
|
| 11 |
+
n_kv_heads = 8
|
| 12 |
+
n_layers = 32
|
| 13 |
+
n_tp = 2
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
weights = {}
|
| 17 |
+
|
| 18 |
+
# embedding
|
| 19 |
+
embedding_weights = []
|
| 20 |
+
for i in range(n_tp):
|
| 21 |
+
path = f"{input_dir_path}/layer_01-model_0{i}-model_states.pt"
|
| 22 |
+
checkpoint = torch.load(path)
|
| 23 |
+
|
| 24 |
+
embedding_weights.append(checkpoint["word_embeddings.weight"].bfloat16())
|
| 25 |
+
|
| 26 |
+
weights[f"model.embed_tokens.weight"] = torch.cat(embedding_weights, dim=0)
|
| 27 |
+
del embedding_weights
|
| 28 |
+
|
| 29 |
+
lm_head_weights = []
|
| 30 |
+
for i in range(n_tp):
|
| 31 |
+
path = f"{input_dir_path}/layer_{n_layers + 5}-model_0{i}-model_states.pt"
|
| 32 |
+
checkpoint = torch.load(path)
|
| 33 |
+
|
| 34 |
+
lm_head_weights.append(checkpoint["lm_head.weight"].bfloat16())
|
| 35 |
+
|
| 36 |
+
weights[f"lm_head.weight"] = torch.cat(lm_head_weights, dim=0)
|
| 37 |
+
del lm_head_weights
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
# transformer layers
|
| 41 |
+
for layer in tqdm(range(n_layers)):
|
| 42 |
+
q_weights, k_weights, v_weights, o_weights = [], [], [], []
|
| 43 |
+
up_weights, gate_weights, down_weights = [], [], []
|
| 44 |
+
|
| 45 |
+
for i in range(n_tp):
|
| 46 |
+
path = f"{input_dir_path}/layer_{layer+3:02d}-model_0{i}-model_states.pt"
|
| 47 |
+
checkpoint = torch.load(path)
|
| 48 |
+
|
| 49 |
+
weights[f"model.layers.{layer}.input_layernorm.weight"] = checkpoint["input_layernorm.weight"].bfloat16()
|
| 50 |
+
weights[f"model.layers.{layer}.post_attention_layernorm.weight"] = checkpoint["post_attention_layernorm.weight"].bfloat16()
|
| 51 |
+
|
| 52 |
+
kv_weight = checkpoint["self_attention.key_value.weight"].bfloat16()
|
| 53 |
+
k_weight, v_weight = torch.chunk(kv_weight, 2, dim=0)
|
| 54 |
+
k_weights.append(k_weight)
|
| 55 |
+
v_weights.append(v_weight)
|
| 56 |
+
|
| 57 |
+
q_weights.append(checkpoint["self_attention.query.weight"].bfloat16())
|
| 58 |
+
o_weights.append(checkpoint["self_attention.dense.weight"].bfloat16())
|
| 59 |
+
down_weights.append(checkpoint["mlp.dense_4h_to_h.weight"].bfloat16())
|
| 60 |
+
|
| 61 |
+
up_gate_weight = checkpoint["mlp.dense_h_to_4h.weight"].bfloat16()
|
| 62 |
+
up_weight, gate_weight = torch.chunk(up_gate_weight, 2, dim=0)
|
| 63 |
+
up_weights.append(up_weight)
|
| 64 |
+
gate_weights.append(gate_weight)
|
| 65 |
+
|
| 66 |
+
weights[f"model.layers.{layer}.self_attn.q_proj.weight"] = torch.cat(q_weights, dim=0)
|
| 67 |
+
weights[f"model.layers.{layer}.self_attn.k_proj.weight"] = torch.cat(k_weights, dim=0)
|
| 68 |
+
weights[f"model.layers.{layer}.self_attn.v_proj.weight"] = torch.cat(v_weights, dim=0)
|
| 69 |
+
weights[f"model.layers.{layer}.self_attn.o_proj.weight"] = torch.cat(o_weights, dim=1)
|
| 70 |
+
weights[f"model.layers.{layer}.mlp.up_proj.weight"] = torch.cat(up_weights, dim=0)
|
| 71 |
+
weights[f"model.layers.{layer}.mlp.gate_proj.weight"] = torch.cat(gate_weights, dim=0)
|
| 72 |
+
weights[f"model.layers.{layer}.mlp.down_proj.weight"] = torch.cat(down_weights, dim=1)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
# output layer norm
|
| 76 |
+
path = f"{input_dir_path}/layer_{n_layers + 4}-model_00-model_states.pt"
|
| 77 |
+
checkpoint = torch.load(path)
|
| 78 |
+
|
| 79 |
+
weights[f"model.norm.weight"] = checkpoint["weight"].bfloat16()
|
| 80 |
+
|
| 81 |
+
torch.save(weights, f"{output_dir_path}/pytorch_model.bin")
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9974eba4a7d380ce3a1710693dfa814512bcf2bd9360af3159da7b5a715475fc
|
| 3 |
+
size 14496143545
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "sep_token": "</s>", "cls_token": "</s>"}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"unk_token": "<unk>", "eos_token": "</s>", "bos_token": "<s>", "tokenizer_class": "PreTrainedTokenizerFast"}
|
| 2 |
+
|