Instructions to use stabilityai/stablecode-instruct-alpha-3b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use stabilityai/stablecode-instruct-alpha-3b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="stabilityai/stablecode-instruct-alpha-3b")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("stabilityai/stablecode-instruct-alpha-3b") model = AutoModelForCausalLM.from_pretrained("stabilityai/stablecode-instruct-alpha-3b") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use stabilityai/stablecode-instruct-alpha-3b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "stabilityai/stablecode-instruct-alpha-3b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "stabilityai/stablecode-instruct-alpha-3b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/stabilityai/stablecode-instruct-alpha-3b
- SGLang
How to use stabilityai/stablecode-instruct-alpha-3b 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 "stabilityai/stablecode-instruct-alpha-3b" \ --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": "stabilityai/stablecode-instruct-alpha-3b", "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 "stabilityai/stablecode-instruct-alpha-3b" \ --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": "stabilityai/stablecode-instruct-alpha-3b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use stabilityai/stablecode-instruct-alpha-3b with Docker Model Runner:
docker model run hf.co/stabilityai/stablecode-instruct-alpha-3b
Fix code sample to resolve ValueError
The current code sample results in an error:
ValueError: The following
model_kwargsare not used by the model: ['token_type_ids']
Adding return_token_type_ids=Falseas an argument to the tokenizer() method resolves this error.
inputs = tokenizer("###Instruction\nGenerate a python function to find number of CPU cores###Response\n", return_tensors="pt", return_token_type_ids=False).to("cuda")
Thanks, came here to post this but where do you put this exactly?
Thanks, came here to post this but where do you put this exactly?
It's passed to the tokenizer, you can see observe in Files changed (next to this discussion).
I am getting this error when I try to use in pipeline 'Repo model stabilityai/stablecode-instruct-alpha-3b is gated. You must be authenticated to access it.'
@sudhir2016 you can use the HuggingFace CLI to login, it will ask you for a token there. Generate a token in your settings. After that, your downloads should start working.
Thanks, came here to post this but where do you put this exactly?
You have to add the parameter return_token_type_ids=False to the tokenizer(...) function.
inputs = tokenizer(
"###Instruction\nGenerate a python function to find number of CPU cores###Response\n",
return_tensors="pt",
return_token_type_ids=False, # <------------- put this here
).to("cuda")
Even example code is wrong !!! faint
@mendhak I did what you suggested. I am using colab. I logged in successfully using login(). Then tried download like this 'hf_hub_download(repo_id="stabilityai/stablecode-instruct-alpha-3b", filename="config.json"). Still getting this error. Cannot access gated repo for url https://huggingface.co/stabilityai/stablecode-instruct-alpha-3b/resolve/main/config.json.
Access to model stabilityai/stablecode-instruct-alpha-3b is restricted and you are not in the authorized list.
After changing as per the above mentioned code, I am getting
OutOfMemoryError: CUDA out of memory. Tried to allocate 38.00 MiB (GPU 0; 14.75 GiB total capacity; 14.51 GiB already allocated; 16.81 MiB free; 14.63 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation.
I am using below code:
model_id='google/flan-t5-large'
tokenizer=AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSeq2SeqLM.from_pretrained(model_id,device_map='auto')
local_llm = HuggingFacePipeline(pipeline=pipeline)
prompt = PromptTemplate(
input_variables=["name"],
template="Tell me about foootballer {name}"
)
chain = LLMChain(llm=local_llm, prompt=prompt)
chain.run("Cristiano Ronaldo")
I am getting this error:
ValueError: The following model_kwargs are not used by the model: ['return_full_text'] (note: typos in the generate arguments will also show up in this list)