Run this model with HF Jobs
Run Tonic/mistralmed 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 to fine-tune https://huggingface.co/Tonic/mistralmed. 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/Tonic/mistralmed 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.
Instructions to use Tonic/mistralmed with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use Tonic/mistralmed with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-v0.1") model = PeftModel.from_pretrained(base_model, "Tonic/mistralmed") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files75 unmodified lines76777879808182838485868788899091929394959697989910010117 unmodified lines1191201211221231241257 unmodified lines1331341351361371381399 unmodified lines14915015115215315415515615715 unmodified lines17317417517617717817918018118218318418518675 unmodified linesfrom peft import PeftModel, PeftConfigimport torchimport gradio as gr# Functions to Wrap the Prompt Correctlydef wrap_text(text, width=90):lines = text.split('\n')wrapped_lines = [textwrap.fill(line, width=width) for line in lines]wrapped_text = '\n'.join(wrapped_lines)return wrapped_textdef multimodal_prompt(input_text, system_prompt="", max_length=512):"""Generates text using a large language model, given a prompt and a device.Args:input_text: The input text to generate a response for.system_prompt: Optional system prompt.max_length: Maximum length of the generated text.Returns:A string containing the generated text."""# Modify the input text to include the desired formatformatted_input = f"""<s>[INST]{input_text}[/INST]"""# Encode the input textencodeds = tokenizer(formatted_input, return_tensors="pt", add_special_tokens=False)17 unmodified linesreturn response_text# Define the devicedevice = "cuda" if torch.cuda.is_available() else "cpu"7 unmodified linestokenizer.pad_token = tokenizer.eos_tokentokenizer.padding_side = 'left'# Specify the configuration class for the model#model_config = AutoConfig.from_pretrained(base_model_id)9 unmodified linesdef __init__(self):self.history = []def predict(self, input_text):# Encode user inputuser_input_ids = tokenizer.encode(input_text, return_tensors="pt")# Concatenate the user input with chat historyif len(self.history) > 0:15 unmodified linestitle = "👋🏻Welcome to Tonic's MistralMed Chat🚀"description = "You can use this Space to test out the current model (MistralMed) or duplicate this Space and use it for any other model on 🤗HuggingFace. Join me on Discord to build together."examples = [["What is the boiling point of nitrogen?"]]iface = gr.Interface(fn=bot.predict,title=title,description=description,examples=examples,inputs="text",outputs="text",theme="ParityError/Anime")75 unmodified lines76777879808182838485868788899091929394959697989910017 unmodified lines1181191201211221237 unmodified lines1311321331341351369 unmodified lines14614714814915015115215315415515615715 unmodified lines17317417517617717817918018118218318418518675 unmodified linesfrom peft import PeftModel, PeftConfigimport torchimport gradio as gr# Functions to Wrap the Prompt Correctlydef wrap_text(text, width=90):lines = text.split('\n')wrapped_lines = [textwrap.fill(line, width=width) for line in lines]wrapped_text = '\n'.join(wrapped_lines)return wrapped_textdef multimodal_prompt(user_input, system_prompt="You are an expert medical analyst:"):"""Generates text using a large language model, given a user input and a system prompt.Args:user_input: The user's input text to generate a response for.system_prompt: Optional system prompt.Returns:A string containing the generated text."""# Combine user input and system promptformatted_input = f"<s>[INST]{system_prompt} {user_input}[/INST]"# Encode the input textencodeds = tokenizer(formatted_input, return_tensors="pt", add_special_tokens=False)17 unmodified linesreturn response_text# Define the devicedevice = "cuda" if torch.cuda.is_available() else "cpu"7 unmodified linestokenizer.pad_token = tokenizer.eos_tokentokenizer.padding_side = 'left'# Specify the configuration class for the model#model_config = AutoConfig.from_pretrained(base_model_id)9 unmodified linesdef __init__(self):self.history = []def predict(self, user_input, system_prompt="You are an expert medical analyst:"):# Combine user input and system promptformatted_input = f"<s>[INST]{system_prompt} {user_input}[/INST]"# Encode user inputuser_input_ids = tokenizer.encode(formatted_input, return_tensors="pt")# Concatenate the user input with chat historyif len(self.history) > 0:15 unmodified linestitle = "👋🏻Welcome to Tonic's MistralMed Chat🚀"description = "You can use this Space to test out the current model (MistralMed) or duplicate this Space and use it for any other model on 🤗HuggingFace. Join me on Discord to build together."examples = [["What is the proper treatment for buccal herpes?"]]iface = gr.Interface(fn=bot.predict,title=title,description=description,examples=examples,inputs=["text", "text"], # Take user input and system prompt separatelyoutputs="text",theme="ParityError/Anime")
README.md+13-13