Text Generation
Transformers
PyTorch
English
RefinedWeb
feature-extraction
custom_code
text-generation-inference
Instructions to use jinaai/falcon-40b-code-alpaca with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use jinaai/falcon-40b-code-alpaca with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="jinaai/falcon-40b-code-alpaca", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("jinaai/falcon-40b-code-alpaca", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use jinaai/falcon-40b-code-alpaca with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "jinaai/falcon-40b-code-alpaca" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "jinaai/falcon-40b-code-alpaca", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/jinaai/falcon-40b-code-alpaca
- SGLang
How to use jinaai/falcon-40b-code-alpaca 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 "jinaai/falcon-40b-code-alpaca" \ --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": "jinaai/falcon-40b-code-alpaca", "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 "jinaai/falcon-40b-code-alpaca" \ --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": "jinaai/falcon-40b-code-alpaca", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use jinaai/falcon-40b-code-alpaca with Docker Model Runner:
docker model run hf.co/jinaai/falcon-40b-code-alpaca
LLM Generation models trained by Jina AI, Finetuner team.
This repo contains the full weights (16bit) for Falcon-40b fit on the Code Alpaca dataset.
Reproduction
This version of the weights was trained with the following hyperparameters:
- Epochs: 2
- Batch size: 128
- Micro batch size: 4
- Learning rate: 3e-4
- Lora r: 8
- Lora target modules: query_key_value
You can reproduce using this repository:
https://github.com/jina-ai/jerboa
Make sure you install requirements and finetune using this command using the following command:
python finetune.py \
--base-model tiiuae/falcon-40b --lora-target-modules query_key_value \
--data-path sahil2801/CodeAlpaca-20k --output-dir ./lora-alpaca-code \
--batch-size 128 --micro-batch-size 4 --eval-limit 45 \
--eval-file code_eval.jsonl --wandb-project jerboa --wandb-log-model \
--wandb-watch gradients --num-epochs 2
Inference
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
TOKENIZER_SOURCE = 'tiiuae/falcon-40b'
BASE_MODEL = 'jinaai/falcon-40b-code-alpaca'
DEVICE = "cuda"
PROMPT = """
Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
### Instruction:
Write a for loop in python
### Input:
### Response:
"""
model = AutoModelForCausalLM.from_pretrained(
pretrained_model_name_or_path=BASE_MODEL,
torch_dtype=torch.float16,
trust_remote_code=True,
device_map='auto',
)
model.eval()
tokenizer = AutoTokenizer.from_pretrained(
TOKENIZER_SOURCE,
trust_remote_code=True,
padding_side='left',
)
tokenizer.pad_token = tokenizer.eos_token
inputs = tokenizer(PROMPT, return_tensors="pt")
input_ids = inputs["input_ids"].to(DEVICE)
input_attention_mask = inputs["attention_mask"].to(DEVICE)
with torch.no_grad():
generation_output = model.generate(
input_ids=input_ids,
attention_mask=input_attention_mask,
return_dict_in_generate=True,
max_new_tokens=32,
eos_token_id=tokenizer.eos_token_id,
)
generation_output = generation_output.sequences[0]
output = tokenizer.decode(generation_output, skip_special_tokens=True)
print(output)
Contact
Join our Discord community and chat with other community members about ideas.
- Downloads last month
- 15