Instructions to use bigcode/starcoder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use bigcode/starcoder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="bigcode/starcoder")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("bigcode/starcoder") model = AutoModelForCausalLM.from_pretrained("bigcode/starcoder") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use bigcode/starcoder with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "bigcode/starcoder" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "bigcode/starcoder", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/bigcode/starcoder
- SGLang
How to use bigcode/starcoder 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 "bigcode/starcoder" \ --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": "bigcode/starcoder", "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 "bigcode/starcoder" \ --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": "bigcode/starcoder", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use bigcode/starcoder with Docker Model Runner:
docker model run hf.co/bigcode/starcoder
Unable to load model, error
KeyError Traceback (most recent call last)
/tmp/ipykernel_1050494/2718782402.py in
2 tokenizer = AutoTokenizer.from_pretrained(checkpoint,use_auth_token=True)
3 # to save memory consider using fp16 or bf16 by specifying torch.dtype=torch.float16 for example
----> 4 model = AutoModelForCausalLM.from_pretrained(checkpoint,use_auth_token=True).to(device)
~/anaconda3/envs/verilog_gpt/lib/python3.9/site-packages/transformers/models/auto/auto_factory.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
421 kwargs["_from_auto"] = True
422 if not isinstance(config, PretrainedConfig):
--> 423 config, kwargs = AutoConfig.from_pretrained(
424 pretrained_model_name_or_path, return_unused_kwargs=True, trust_remote_code=trust_remote_code, **kwargs
425 )
~/anaconda3/envs/verilog_gpt/lib/python3.9/site-packages/transformers/models/auto/configuration_auto.py in from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
743 return config_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
744 elif "model_type" in config_dict:
--> 745 config_class = CONFIG_MAPPING[config_dict["model_type"]]
746 return config_class.from_dict(config_dict, **kwargs)
747 else:
~/anaconda3/envs/verilog_gpt/lib/python3.9/site-packages/transformers/models/auto/configuration_auto.py in getitem(self, key)
450 return self._extra_content[key]
451 if key not in self._mapping:
--> 452 raise KeyError(key)
453 value = self._mapping[key]
454 module_name = model_type_to_module_name(key)
KeyError: 'gpt_bigcode'
I am receiving the same error.
8 tokenizer = AutoTokenizer.from_pretrained(checkpoint)
----> 9 model = AutoModelForCausalLM.from_pretrained(checkpoint)#.to(device)
File ~/mambaforge/envs/llm/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py:441, in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
438 if kwargs_copy.get("torch_dtype", None) == "auto":
439 _ = kwargs_copy.pop("torch_dtype")
--> 441 config, kwargs = AutoConfig.from_pretrained(
442 pretrained_model_name_or_path,
443 return_unused_kwargs=True,
444 trust_remote_code=trust_remote_code,
445 **hub_kwargs,
446 **kwargs_copy,
447 )
448 if hasattr(config, "auto_map") and cls.__name__ in config.auto_map:
449 if not trust_remote_code:
File ~/mambaforge/envs/llm/lib/python3.10/site-packages/transformers/models/auto/configuration_auto.py:911, in AutoConfig.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
909 return config_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
910 elif "model_type" in config_dict:
--> 911 config_class = CONFIG_MAPPING[config_dict["model_type"]]
912 return config_class.from_dict(config_dict, **unused_kwargs)
913 else:
914 # Fallback: use pattern matching on the string.
915 # We go from longer names to shorter names to catch roberta before bert (for instance)
File ~/mambaforge/envs/llm/lib/python3.10/site-packages/transformers/models/auto/configuration_auto.py:617, in _LazyConfigMapping.__getitem__(self, key)
615 return self._extra_content[key]
616 if key not in self._mapping:
--> 617 raise KeyError(key)
618 value = self._mapping[key]
619 module_name = model_type_to_module_name(key)
KeyError: 'gpt_bigcode'
Install the latest version of transformers (should be 4.28.1): https://huggingface.co/docs/transformers/installation
e.g. conda install -c huggingface transformers installs 4.28.1 instead of 4.24.0 with conda install transformers
I have the latest version (transformers-4.29.0.dev0) of transformer installed from source
pip install git+https://github.com/huggingface/transformers
Its loading now, there was a conflicting lower version of transformer on my machine
It's loading now, there was a conflicting lower version of the transformer on my machine.
It's loading now, there was a conflicting lower version of the transformer on my machine.