Views
No views yet
transformers from main until transformers=4.39.0 is released.pip install git+https://github.com/huggingface/transformers@maincausal-conv1d and mamba-ssm using:1pip install causal-conv1d>=1.2.0
2pip install mamba-ssm>=1.2.0CUDA kernels will be used.1from transformers import MambaConfig, MambaForCausalLM, AutoTokenizer
2import torch
3
4if model_has_instruct_data:
5 # use chat tokens
6 prompt = ”<start_user>Tell me something about Paris.<end_message><start_assistant>”
7else:
8 # prompt the non-instructed tuned model gently
9 prompt = ”This is a text about Paris. Paris is”
10
11tokenizer = AutoTokenizer.from_pretrained("lightonai/mambaoutai")
12model = MambaForCausalLM.from_pretrained("lightonai/mambaoutai")
13input_ids = tokenizer(prompt, return_tensors="pt")["input_ids"]
14
15out = model.generate(input_ids, max_new_tokens=10)
16print(tokenizer.batch_decode(out))revision parameter to the from_pretrained method.
For example, to load the model checkpoint after 30000 steps of pretraining, you can use the following code:1from transformers import MambaConfig, MambaForCausalLM, AutoTokenizer
2import torch
3
4tokenizer = AutoTokenizer.from_pretrained("lightonai/mambaoutai", revision="pre-30000")
5model = MambaForCausalLM.from_pretrained("lightonai/mambaoutai", revision="pre-30000")
6input_ids = tokenizer("What is a mamba?", return_tensors="pt")["input_ids"]
7
8out = model.generate(input_ids, max_new_tokens=10)
9print(tokenizer.batch_decode(out))1# Clone llama.cpp repository and compile it from source
2git clone https://github.com/ggerganov/llama.cpp\
3cd llama.cpp
4make
5
6# Create a venv and install dependencies
7conda create -n mamba-cpp python=3.10
8conda activate mamba-cpp
9pip install -r requirements/requirements-convert-hf-to-gguf.txt
10
11# Download the weights, tokenizer, config, tokenizer_config and special_tokens_map from this repo and
12# put them in a directory 'Mambaoutai/'
13mkdir Mambaoutai
14
15# Convert the weights to GGUF format
16python convert-hf-to-gguf.py Mambaoutai
17
18# Run inference with a prompt
19./main -m Mambaoutai/ggml-model-f16.gguf -p "Building a website can be done in 10 simple steps:\nStep 1:" -n 400 -e -ngl 1| Parameter | Value |
|---|---|
| d_model | 2688 |
| n_layer | 28 |
| vocab_size | 65024 |
| context_len | 4096 |
| rms_norm | true |
| residual_in_fp32 | true |
| fused_add_norm | true |
| conv_kernel | 4 |
| d_inner | 5376 |
| state_size | 16 |
| dtype | bfloat16 |
| tie_word_embeddings | false |
| non embeddings params | 1.27B |