Instructions to use parallelstudios/mpt-7b-instruct-parallel-colony-memory-importance-ft with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use parallelstudios/mpt-7b-instruct-parallel-colony-memory-importance-ft with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="parallelstudios/mpt-7b-instruct-parallel-colony-memory-importance-ft", trust_remote_code=True)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("parallelstudios/mpt-7b-instruct-parallel-colony-memory-importance-ft", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("parallelstudios/mpt-7b-instruct-parallel-colony-memory-importance-ft", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use parallelstudios/mpt-7b-instruct-parallel-colony-memory-importance-ft with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "parallelstudios/mpt-7b-instruct-parallel-colony-memory-importance-ft" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "parallelstudios/mpt-7b-instruct-parallel-colony-memory-importance-ft", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/parallelstudios/mpt-7b-instruct-parallel-colony-memory-importance-ft
- SGLang
How to use parallelstudios/mpt-7b-instruct-parallel-colony-memory-importance-ft 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 "parallelstudios/mpt-7b-instruct-parallel-colony-memory-importance-ft" \ --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": "parallelstudios/mpt-7b-instruct-parallel-colony-memory-importance-ft", "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 "parallelstudios/mpt-7b-instruct-parallel-colony-memory-importance-ft" \ --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": "parallelstudios/mpt-7b-instruct-parallel-colony-memory-importance-ft", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use parallelstudios/mpt-7b-instruct-parallel-colony-memory-importance-ft with Docker Model Runner:
docker model run hf.co/parallelstudios/mpt-7b-instruct-parallel-colony-memory-importance-ft
File size: 2,861 Bytes
225c8e1 fda667f 225c8e1 fda667f 55522d5 840ecaa cd95ea8 840ecaa fda667f 225c8e1 840ecaa 225c8e1 840ecaa 225c8e1 840ecaa fda667f 840ecaa 225c8e1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | import warnings
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from typing import Any, Dict
class EndpointHandler:
INSTRUCTION_KEY = "### Instruction:"
RESPONSE_KEY = "### Response:"
END_KEY = "### End"
INTRO_BLURB = "Below is an instruction that describes a task. Write a response that appropriately completes the request."
PROMPT_FOR_GENERATION_FORMAT = """{intro}
{instruction_key}
{instruction}
{response_key}
""".format(
intro=INTRO_BLURB,
instruction_key=INSTRUCTION_KEY,
instruction="{instruction}",
response_key=RESPONSE_KEY,
)
def __init__(
self,
path,
torch_dtype=torch.bfloat16,
trust_remote_code=True,
) -> None:
self.model = AutoModelForCausalLM.from_pretrained(
path,
torch_dtype=torch_dtype,
trust_remote_code=trust_remote_code
)
tokenizer = AutoTokenizer.from_pretrained(
"mosaicml/mpt-7b-instruct",
trust_remote_code=trust_remote_code
)
if tokenizer.pad_token_id is None:
warnings.warn(
"pad_token_id is not set for the tokenizer. Using eos_token_id as pad_token_id."
)
tokenizer.pad_token = tokenizer.eos_token
tokenizer.padding_side = "right"
self.tokenizer = tokenizer
self.device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
self.model.eval()
self.model.to(device=self.device, dtype=torch_dtype)
self.generate_kwargs = {
"temperature": 0.01,
"top_p": 0.92,
"top_k": 0,
"max_new_tokens": 512,
"use_cache": True,
"do_sample": True,
"eos_token_id": self.tokenizer.eos_token_id,
"pad_token_id": self.tokenizer.pad_token_id,
"repetition_penalty": 1.0
}
def format_instruction(self, instruction):
return self.PROMPT_FOR_GENERATION_FORMAT.format(instruction=instruction)
def __call__(self, data: Dict[str, Any]) -> Dict[str, str]:
# process input
inputs = data.pop("inputs", data)
parameters = data.pop("parameters", None)
# preprocess
s = self.format_instruction(instruction=inputs)
input_ids = self.tokenizer(s, return_tensors="pt").input_ids.to(self.device)
gkw = {**self.generate_kwargs, **parameters}
# pass inputs with all kwargs in data
with torch.no_grad():
output_ids = self.model.generate(input_ids, **gkw)
# Slice the output_ids tensor to get only new tokens
new_tokens = output_ids[0, len(input_ids[0]) :]
output_text = self.tokenizer.decode(new_tokens, skip_special_tokens=True)
return [{"generated_text": output_text}] |