Run this model with HF Jobs
Run piercemaloney/llemma_7b on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/piercemaloney/llemma_7b. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/piercemaloney/llemma_7b on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/piercemaloney/llemma_7b. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/piercemaloney/llemma_7b. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use piercemaloney/llemma_7b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use piercemaloney/llemma_7b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="piercemaloney/llemma_7b")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("piercemaloney/llemma_7b") model = AutoModelForCausalLM.from_pretrained("piercemaloney/llemma_7b", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use piercemaloney/llemma_7b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "piercemaloney/llemma_7b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "piercemaloney/llemma_7b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/piercemaloney/llemma_7b
- SGLang
How to use piercemaloney/llemma_7b 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 "piercemaloney/llemma_7b" \ --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": "piercemaloney/llemma_7b", "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 "piercemaloney/llemma_7b" \ --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": "piercemaloney/llemma_7b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use piercemaloney/llemma_7b with Docker Model Runner:
docker model run hf.co/piercemaloney/llemma_7b
Pierce Maloney commited on
Commit ·
dee492f
1
Parent(s): 813fd4a
back to .generate. forgot about returning gen ids
Browse files1 unmodified line234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495961 unmodified linefrom transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, StoppingCriteria, StoppingCriteriaList# class EndpointHandler():# def __init__(self, path=""):# tokenizer = AutoTokenizer.from_pretrained(path)# tokenizer.pad_token = tokenizer.eos_token# self.model = AutoModelForCausalLM.from_pretrained(path).to('cuda')# self.tokenizer = tokenizer# self.stopping_criteria = StoppingCriteriaList([StopAtPeriodCriteria(tokenizer)])# def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:# """# data args:# inputs (:obj: `str`)# kwargs# Return:# A :obj:`list` | `dict`: will be serialized and returned# """# inputs = data.pop("inputs", data)# additional_bad_words_ids = data.pop("additional_bad_words_ids", [])# # 3070, 10456, [313, 334] corresponds to "(*", and we do not want to output a comment# # 13 is a newline character# # [1976, 441, 29889], [4920, 441, 29889] is "Abort." [4920, 18054, 29889] is "Aborted."# # [2087, 29885, 4430, 29889] is "Admitted."# bad_words_ids = [[3070], [313, 334], [10456], [13], [1976, 441, 29889], [2087, 29885, 4430, 29889], [4920, 441], [4920, 441, 29889], [4920, 18054, 29889]]# bad_words_ids.extend(additional_bad_words_ids)# input_ids = self.tokenizer.encode(inputs, return_tensors="pt").to('cuda')# max_generation_length = 75 # Desired number of tokens to generate# # max_input_length = 4092 - max_generation_length # Maximum input length to allow space for generation# # # Truncate input_ids to the most recent tokens that fit within the max_input_length# # if input_ids.shape[1] > max_input_length:# # input_ids = input_ids[:, -max_input_length:]# max_length = input_ids.shape[1] + max_generation_length# generated_ids = self.model.generate(# input_ids,# max_length=max_length, # 50 new tokens# bad_words_ids=bad_words_ids,# temperature=1,# top_k=40,# do_sample=True,# stopping_criteria=self.stopping_criteria,# )# generated_text = self.tokenizer.decode(generated_ids[0][input_ids.shape[1]:], skip_special_tokens=True)# prediction = [{"generated_text": generated_text, "generated_ids": generated_ids[0][input_ids.shape[1]:].tolist()}]# return predictionclass EndpointHandler():def __init__(self, path=""):self.model_path = pathtokenizer = AutoTokenizer.from_pretrained(path)tokenizer.pad_token = tokenizer.eos_tokenself.tokenizer = tokenizer# Initialize the pipeline for text generationself.text_generation_pipeline = pipeline("text-generation", model=path, tokenizer=self.tokenizer, device=0) # device=0 for CUDAdef __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:"""data args:inputs (:obj: `str`)kwargsReturn:A :obj:`list` | `dict`: will be serialized and returned"""inputs = data.pop("inputs", data)additional_bad_words_ids = data.pop("additional_bad_words_ids", [])# Define bad words to avoid in the outputbad_words_ids = [[3070], [313, 334], [10456], [13], [1976, 441, 29889], [2087, 29885, 4430, 29889], [4920, 441], [4920, 441, 29889], [4920, 18054, 29889]]bad_words_ids.extend(additional_bad_words_ids)# Generate text using the pipelinegeneration_kwargs = {"max_new_tokens": 75,"temperature": 0.7,"top_k": 40,"bad_words_ids": bad_words_ids,"pad_token_id": self.tokenizer.eos_token_id,"return_full_text": False, # Only return the new generated tokens}generated_outputs = self.text_generation_pipeline(inputs, **generation_kwargs)# Format the outputpredictions = [{"generated_text": output["generated_text"]} for output in generated_outputs]return predictionsclass StopAtPeriodCriteria(StoppingCriteria):1 unmodified line234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556571 unmodified linefrom transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, StoppingCriteria, StoppingCriteriaListclass EndpointHandler():def __init__(self, path=""):tokenizer = AutoTokenizer.from_pretrained(path)tokenizer.pad_token = tokenizer.eos_tokenself.model = AutoModelForCausalLM.from_pretrained(path).to('cuda')self.tokenizer = tokenizerself.stopping_criteria = StoppingCriteriaList([StopAtPeriodCriteria(tokenizer)])def __call__(self, data: Dict[str, Any]) -> List[Dict[str, Any]]:"""data args:inputs (:obj: `str`)kwargsReturn:A :obj:`list` | `dict`: will be serialized and returned"""inputs = data.pop("inputs", data)additional_bad_words_ids = data.pop("additional_bad_words_ids", [])# 3070, 10456, [313, 334] corresponds to "(*", and we do not want to output a comment# 13 is a newline character# [1976, 441, 29889], [4920, 441, 29889] is "Abort." [4920, 18054, 29889] is "Aborted."# [2087, 29885, 4430, 29889] is "Admitted."bad_words_ids = [[3070], [313, 334], [10456], [13], [1976, 441, 29889], [2087, 29885, 4430, 29889], [4920, 441], [4920, 441, 29889], [4920, 18054, 29889]]bad_words_ids.extend(additional_bad_words_ids)input_ids = self.tokenizer.encode(inputs, return_tensors="pt").to('cuda')max_generation_length = 75 # Desired number of tokens to generate# max_input_length = 4092 - max_generation_length # Maximum input length to allow space for generation# # Truncate input_ids to the most recent tokens that fit within the max_input_length# if input_ids.shape[1] > max_input_length:# input_ids = input_ids[:, -max_input_length:]max_length = input_ids.shape[1] + max_generation_lengthgenerated_ids = self.model.generate(input_ids,max_length=max_length, # 50 new tokensbad_words_ids=bad_words_ids,temperature=1,top_k=40,do_sample=True,stopping_criteria=self.stopping_criteria,)generated_text = self.tokenizer.decode(generated_ids[0][input_ids.shape[1]:], skip_special_tokens=True)prediction = [{"generated_text": generated_text, "generated_ids": generated_ids[0][input_ids.shape[1]:].tolist()}]return predictionclass StopAtPeriodCriteria(StoppingCriteria):
handler.py+34-73