Instructions to use vikp/llama_coder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use vikp/llama_coder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="vikp/llama_coder", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("vikp/llama_coder", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("vikp/llama_coder", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use vikp/llama_coder with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "vikp/llama_coder" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "vikp/llama_coder", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/vikp/llama_coder
- SGLang
How to use vikp/llama_coder 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 "vikp/llama_coder" \ --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": "vikp/llama_coder", "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 "vikp/llama_coder" \ --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": "vikp/llama_coder", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use vikp/llama_coder with Docker Model Runner:
docker model run hf.co/vikp/llama_coder
| from transformers.models.llama.modeling_llama import LlamaForCausalLM, LlamaAttention, LlamaRotaryEmbedding | |
| from transformers.models.llama.configuration_llama import LlamaConfig | |
| import torch | |
| class CodeLlamaConfig(LlamaConfig): | |
| def __init__(self, **kwargs): | |
| super().__init__(**kwargs) | |
| self.rope_theta = 10000.0 | |
| if kwargs.get("rope_theta"): | |
| try: | |
| self.rope_theta = float(kwargs["rope_theta"]) | |
| print(f"Rope theta set to {self.rope_theta}") | |
| except Exception: | |
| print("Could not set rope theta properly, ensure it is a number") | |
| class CodeLlamaNTKScalingRotaryEmbedding(LlamaRotaryEmbedding): | |
| def __init__(self, dim, max_position_embeddings=2048, base=1000000.0, device=None, scaling_factor=1.0): | |
| self.scaling_factor = scaling_factor | |
| self.base = base | |
| super().__init__(dim, max_position_embeddings, base, device) | |
| def _set_cos_sin_cache(self, seq_len, device, dtype): | |
| self.max_seq_len_cached = seq_len | |
| inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2).float().to(device) / self.dim)) | |
| self.register_buffer("inv_freq", inv_freq, persistent=False) | |
| t = torch.arange(self.max_seq_len_cached, device=device, dtype=self.inv_freq.dtype) | |
| freqs = torch.einsum("i,j->ij", t, self.inv_freq) | |
| # Different from paper, but it uses a different permutation in order to obtain the same calculation | |
| emb = torch.cat((freqs, freqs), dim=-1) | |
| self.register_buffer("cos_cached", emb.cos()[None, None, :, :].to(dtype), persistent=False) | |
| self.register_buffer("sin_cached", emb.sin()[None, None, :, :].to(dtype), persistent=False) | |
| class CodeLlamaForCausalLM(LlamaForCausalLM): | |
| _tied_weights_keys = ["lm_head.weight"] | |
| config_class = CodeLlamaConfig | |
| def __init__(self, config): | |
| super().__init__(config) | |
| for layer in self.model.layers: | |
| attn = layer.self_attn | |
| head_dim = attn.head_dim | |
| max_embeddings = attn.max_position_embeddings | |
| base = config.rope_theta | |
| attn.rotary_emb = CodeLlamaNTKScalingRotaryEmbedding(head_dim, max_embeddings, base=base) | |