Instructions to use state-spaces/mamba-370m-hf with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use state-spaces/mamba-370m-hf with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="state-spaces/mamba-370m-hf")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("state-spaces/mamba-370m-hf") model = AutoModelForCausalLM.from_pretrained("state-spaces/mamba-370m-hf", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use state-spaces/mamba-370m-hf with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "state-spaces/mamba-370m-hf" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "state-spaces/mamba-370m-hf", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/state-spaces/mamba-370m-hf
- SGLang
How to use state-spaces/mamba-370m-hf 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 "state-spaces/mamba-370m-hf" \ --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": "state-spaces/mamba-370m-hf", "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 "state-spaces/mamba-370m-hf" \ --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": "state-spaces/mamba-370m-hf", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use state-spaces/mamba-370m-hf with Docker Model Runner:
docker model run hf.co/state-spaces/mamba-370m-hf
attention mask for mamba-370m-hf model
i am creating a mamba inference pipeline by fetching the state-spaces mamba models (130m and 370m variants).
the mamba model is loaded using the following code snippet :
either - llm = MambaForCausalLM.from_pretrained(model_name)
or - llm = AutoModelForCausalLM.from_pretrained(model_name)
for both these methods, when i try to generate outputs, i receive a warning stating :
"The attention mask is not set and cannot be inferred from input because pad token is same as eos token.As a consequence, you may observe unexpected behavior. Please pass your input's attention_mask to obtain reliable results."
i created the attn_mask for the input tokens :
tokens = llm_model.tokenizer(prompt, return_tensors="pt")
attn_mask = tokens.attention_mask.to(device=device)
and now i am trying to pass it to the model object as a parameter in the generate() function as follows :
llm.generate( input_ids=input_ids, max_new_tokens=50, eos_token_id=llm_model.tokenizer.eos_token_id, attention_mask=attn_mask)
but i receive this error :
ValueError: The following model_kwargs are not used by the model: ['attention_mask']
is there something that i am missing out on? how can i solve this out?
I got the same error too and think it was the result of the new update to the transformers library.
I set it to install version 4.41.0 of Transformers (instead of the most recent) and was able to solve it.
At the time of creation, I also used the newer versions for mamba & causal-conv1d, which didn't seem to be an issue.
mamba-ssm=2.2.2 and causal-conv1d=1.4.0
Hope this helps!