Views
No views yet
mistralai/Magistral-Small-2506 model using a medical reasoning dataset (mamachang/medical-reasoning) with 4-bit quantization for memory-efficient training.nvidia-smi check is included).1from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
2from peft import PeftModel
3import torch
4
5# Base model
6base_model_id = "unsloth/Magistral-Small-2506-bnb-4bit"
7
8# Your fine-tuned LoRA adapter repository
9lora_adapter_id = "kingabzpro/Magistral-Small-Medical-QA"
10
11# Load base model
12base_model = AutoModelForCausalLM.from_pretrained(
13 base_model_id,
14 device_map="auto",
15 torch_dtype=torch.bfloat16,
16 trust_remote_code=True,
17)
18
19# Attach the LoRA adapter
20model = PeftModel.from_pretrained(
21 base_model,
22 lora_adapter_id,
23 device_map="auto",
24 trust_remote_code=True,
25)
26
27# Load tokenizer
28tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
29
30# Inference example
31prompt = """
32Please answer with one of the options in the bracket. Write reasoning in between <analysis></analysis>. Write the answer in between <answer></answer>.
33
34### Question:
35A research group wants to assess the relationship between childhood diet and cardiovascular disease in adulthood.
36A prospective cohort study of 500 children between 10 to 15 years of age is conducted in which the participants' diets are recorded for 1 year and then the patients are assessed 20 years later for the presence of cardiovascular disease.
37A statistically significant association is found between childhood consumption of vegetables and decreased risk of hyperlipidemia and exercise tolerance.
38When these findings are submitted to a scientific journal, a peer reviewer comments that the researchers did not discuss the study's validity.
39Which of the following additional analyses would most likely address the concerns about this study's design?
40{'A': 'Blinding', 'B': 'Crossover', 'C': 'Matching', 'D': 'Stratification', 'E': 'Randomization'},
41### Response:
42<analysis>
43
44"""
45
46inputs = tokenizer(
47 [prompt + tokenizer.eos_token],
48 return_tensors="pt"
49).to("cuda")
50
51outputs = model.generate(
52 input_ids=inputs.input_ids,
53 attention_mask=inputs.attention_mask,
54 max_new_tokens=1200,
55 eos_token_id=tokenizer.eos_token_id,
56 use_cache=True,
57)
58response = tokenizer.batch_decode(outputs, skip_special_tokens=True)
59print(response[0].split("### Response:")[1])<analysis>
Analysis:
This is a prospective cohort study looking at the relationship between childhood diet and cardiovascular disease in adulthood. The key concern from the peer reviewer is about the study's validity.
To address concerns about validity, the researchers could perform additional analyses to control for confounding. Matching and stratification would help control for known confounders like socioeconomic status or family history. Crossover and blinding are not applicable to this observational study design. Randomization would not be possible since the study is observational.
</analysis>
<answer>
D: Stratification
</answer>