Run this model with HF Jobs
Run xu1998hz/InstructScore 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/xu1998hz/InstructScore. 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/xu1998hz/InstructScore 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/xu1998hz/InstructScore. 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/xu1998hz/InstructScore. 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 xu1998hz/InstructScore with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use xu1998hz/InstructScore with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="xu1998hz/InstructScore")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("xu1998hz/InstructScore") model = AutoModelForCausalLM.from_pretrained("xu1998hz/InstructScore", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use xu1998hz/InstructScore with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "xu1998hz/InstructScore" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "xu1998hz/InstructScore", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/xu1998hz/InstructScore
- SGLang
How to use xu1998hz/InstructScore 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 "xu1998hz/InstructScore" \ --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": "xu1998hz/InstructScore", "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 "xu1998hz/InstructScore" \ --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": "xu1998hz/InstructScore", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use xu1998hz/InstructScore with Docker Model Runner:
docker model run hf.co/xu1998hz/InstructScore
Wenda Xu commited on
Commit ·
e31eb42
1
Parent(s): dbfa41c
add running codes
Browse filesFiles changed (4)
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485import torchfrom typing import Dictimport transformersfrom transformers import LlamaForCausalLM, LlamaTokenizer
DEFAULT_PAD_TOKEN = "[PAD]"DEFAULT_EOS_TOKEN = "</s>"DEFAULT_BOS_TOKEN = "</s>"DEFAULT_UNK_TOKEN = "</s>"MAX_SOURCE_LENGTH = 512MAX_TARGET_LENGTH = 512print("Max source length: ", MAX_SOURCE_LENGTH)print("MAX target length: ", MAX_TARGET_LENGTH)
def smart_tokenizer_and_embedding_resize( special_tokens_dict: Dict, tokenizer: transformers.PreTrainedTokenizer,): """Resize tokenizer and embedding. Note: This is the unoptimized version that may make your embedding size not be divisible by 64. """ tokenizer.add_special_tokens(special_tokens_dict) tokenizer.add_special_tokens( { "eos_token": DEFAULT_EOS_TOKEN, "bos_token": DEFAULT_BOS_TOKEN, "unk_token": DEFAULT_UNK_TOKEN, } )
device_id = ( torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu"))
class InstructScore: def __init__(self): self.tokenizer = LlamaTokenizer.from_pretrained( "InstructScore_Tok", model_max_length=MAX_SOURCE_LENGTH, use_fast=False ) # enable batch inference by left padding self.tokenizer.padding_side = "left"
smart_tokenizer_and_embedding_resize( special_tokens_dict=dict(pad_token=DEFAULT_PAD_TOKEN), tokenizer=self.tokenizer, ) self.model = LlamaForCausalLM.from_pretrained('InstructScore_English').to(device_id) self.model.eval() def score(self, ref_ls, out_ls): prompt_ls=\ [f"You are evaluating Chinese-to-English Machine translation task. The correct translation is \"{ref}\". The model generated translation is \"{out}\". Please identify all errors within each model output, up to a maximum of five. For each error, please give me the corresponding error type, major/minor label, error location of the model generated translation and explanation for the error. Major errors can confuse or mislead the reader due to significant change in meaning, while minor\ errors don't lead to loss of meaning but will be noticed." for ref, out in zip(ref_ls, out_ls)]
with torch.no_grad(): inputs = self.tokenizer( prompt_ls, return_tensors="pt", padding=True, truncation=True, max_length=MAX_SOURCE_LENGTH, ) outputs = self.model.generate( inputs["input_ids"].to(device_id), attention_mask=inputs["attention_mask"].to(device_id), max_new_tokens=MAX_TARGET_LENGTH, ) batch_outputs = self.tokenizer.batch_decode( outputs, skip_special_tokens=True, clean_up_tokenization_spaces=True, ) scores_ls = [(-1) * output.count("Major/minor: Minor") + (-5) * output.count("Major/minor: Major") for output in batch_outputs] return batch_outputs, scores_ls
def main(): refs = ["SEScore is a simple but effective next generation text generation evaluation metric", "SEScore it really works"] outs = ["SEScore is a simple effective text evaluation metric for next generation", "SEScore is not working"] scorer = InstructScore() batch_outputs, scores_ls = scorer.score(refs, outs) print(batch_outputs) print(scores_ls)
if __name__ == "__main__": main()1{}123version https://git-lfs.github.com/spec/v1oid sha256:9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347size 499723123456789{ "bos_token": "", "clean_up_tokenization_spaces": false, "eos_token": "", "model_max_length": 1000000000000000019884624838656, "special_tokens_map_file": "/mnt/data3/wendaxu/.cache/huggingface/hub/models--decapoda-research--llama-7b-hf/snapshots/5f98eefcc80e437ef68d457ad7bf167c2c6a1348/special_tokens_map.json", "tokenizer_class": "LlamaTokenizer", "unk_token": ""}InstructScore.pyAdded+85
InstructScore_Tok/special_tokens_map.jsonAdded+1
InstructScore_Tok/tokenizer.modelAdded+3
InstructScore_Tok/tokenizer_config.jsonAdded+9