import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, AutoConfig
from peft import PeftModel, PeftConfig
# step 1: Setup constant
model_name = "StanfordAIMI/SRR-Mistral7b-finetuned"
device = torch.device("cuda"if torch.cuda.is_available() else"cpu")
# step 2: Load Processor and Model
config = PeftConfig.from_pretrained(model_name)
base_model_name_or_path = config.base_model_name_or_path
model = AutoModelForCausalLM.from_pretrained(base_model_name_or_path, trust_remote_code=True, device_map="auto", torch_dtype=torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained(base_model_name_or_path, trust_remote_code=True)
tokenizer.pad_token = tokenizer.eos_token
model = PeftModel.from_pretrained(model, model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, trust_remote_code=True).to(device)
model.eval()
# step 3: Inference (example from MIMIC-CXR dataset)
input_text = "<|system|> You are a radiology expert.<|end|> <|user|>CHEST RADIOGRAPH PERFORMED ON ___ COMPARISON: Prior exam from ___. CLINICAL HISTORY: Weakness, assess pneumonia. FINDINGS: Frontal and lateral views of the chest were provided. Midline sternotomy wires are again noted. The heart is poorly assessed, though remains enlarged. There are at least small bilateral pleural effusions. There may be mild interstitial edema. No pneumothorax. Bony structures are demineralized with kyphotic angulation in the lower T-spine again noted. IMPRESSION: Limited exam with small bilateral effusions, cardiomegaly, and possible mild interstitial edema. <|end|> \n<|assistant|> Output: "
inputs = tokenizer(input_text, padding="max_length", truncation=True, max_length=512, return_tensors="pt")
inputs["attention_mask"] = inputs["input_ids"].ne(tokenizer.pad_token_id) # Add attention mask
input_ids = inputs['input_ids'].to(device)
attention_mask=inputs["attention_mask"].to(device)
generated_ids = model.generate(
input_ids, attention_mask=attention_mask, max_new_tokens=286, min_new_tokens= 120, num_beams=5, early_stopping=True, max_length=None
)[0]
decoded = tokenizer.decode(generated_ids, skip_special_tokens=True)
decoded = decoded.rsplit("Output:", 1)[-1].strip()
print(decoded)
Runs of StanfordAIMI SRR-Mistral7b-finetuned on huggingface.co
0
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs
More Information About SRR-Mistral7b-finetuned huggingface.co Model
SRR-Mistral7b-finetuned huggingface.co
SRR-Mistral7b-finetuned huggingface.co is an AI model on huggingface.co that provides SRR-Mistral7b-finetuned's model effect (), which can be used instantly with this StanfordAIMI SRR-Mistral7b-finetuned model. huggingface.co supports a free trial of the SRR-Mistral7b-finetuned model, and also provides paid use of the SRR-Mistral7b-finetuned. Support call SRR-Mistral7b-finetuned model through api, including Node.js, Python, http.
SRR-Mistral7b-finetuned huggingface.co is an online trial and call api platform, which integrates SRR-Mistral7b-finetuned's modeling effects, including api services, and provides a free online trial of SRR-Mistral7b-finetuned, you can try SRR-Mistral7b-finetuned online for free by clicking the link below.
StanfordAIMI SRR-Mistral7b-finetuned online free url in huggingface.co:
SRR-Mistral7b-finetuned is an open source model from GitHub that offers a free installation service, and any user can find SRR-Mistral7b-finetuned on GitHub to install. At the same time, huggingface.co provides the effect of SRR-Mistral7b-finetuned install, users can directly use SRR-Mistral7b-finetuned installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
SRR-Mistral7b-finetuned install url in huggingface.co: