madan2248c commited on
Commit
1a0e55c
Β·
verified Β·
1 Parent(s): a809106

Upload Clinical Agent Transformer mcp-full artifacts

Browse files
Files changed (1) hide show
  1. README.md +124 -0
README.md CHANGED
@@ -32,6 +32,130 @@ This upload contains the final trained package from the Modal checkpoint volume:
32
 
33
  The `trainable_state.pt` file is important because this project modifies the LLaMA architecture with custom MLA, MoE, recurrent, QK-Norm, post-norm, and MTP components. The adapter files alone do not represent every custom trainable module.
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  ## Training Procedure
36
 
37
  The model was trained in two stages:
 
32
 
33
  The `trainable_state.pt` file is important because this project modifies the LLaMA architecture with custom MLA, MoE, recurrent, QK-Norm, post-norm, and MTP components. The adapter files alone do not represent every custom trainable module.
34
 
35
+ ## Repository Layout
36
+
37
+ ```text
38
+ .
39
+ β”œβ”€β”€ README.md
40
+ β”œβ”€β”€ metrics.json
41
+ β”œβ”€β”€ training_config.json
42
+ β”œβ”€β”€ training_history.csv
43
+ β”œβ”€β”€ losses.csv
44
+ β”œβ”€β”€ loss_curve.png
45
+ β”œβ”€β”€ train_validation_loss.png
46
+ β”œβ”€β”€ validation_perplexity.png
47
+ β”œβ”€β”€ learning_rate.png
48
+ β”œβ”€β”€ trainable_state.pt
49
+ └── model/
50
+ β”œβ”€β”€ adapter_config.json
51
+ └── adapter_model.safetensors
52
+ ```
53
+
54
+ ## How To Clone
55
+
56
+ ```bash
57
+ git lfs install
58
+ git clone https://huggingface.co/madan2248c/clinical-agent-transformer-llama-31-8b
59
+ cd clinical-agent-transformer-llama-31-8b
60
+ ```
61
+
62
+ The repository uses Git LFS because `trainable_state.pt` is large.
63
+
64
+ ## How To Use This Model Package
65
+
66
+ This repository is not a standalone vanilla Hugging Face `AutoModelForCausalLM.from_pretrained(...)` checkpoint. It is a Clinical Agent Transformer package with:
67
+
68
+ 1. the original gated base model dependency, `meta-llama/Llama-3.1-8B-Instruct`;
69
+ 2. PEFT/LoRA adapter weights in `model/`;
70
+ 3. custom architecture trainable weights in `trainable_state.pt`;
71
+ 4. project code that applies the architecture surgery before loading the trained state.
72
+
73
+ To use it correctly, clone this project codebase and load the model through the same architecture path used during training.
74
+
75
+ ### Install Runtime Dependencies
76
+
77
+ ```bash
78
+ pip install torch transformers==4.52.4 peft accelerate bitsandbytes huggingface_hub
79
+ ```
80
+
81
+ You must also have access to the gated LLaMA base model and be logged in:
82
+
83
+ ```bash
84
+ huggingface-cli login
85
+ ```
86
+
87
+ ### Example Loading Code
88
+
89
+ ```python
90
+ import torch
91
+ from huggingface_hub import hf_hub_download
92
+ from peft import PeftModel
93
+
94
+ from llama_surgery.config import AdapterConfig, SurgeryConfig, TrainingConfig
95
+ from llama_surgery.model import load_model, load_tokenizer
96
+
97
+ repo_id = "madan2248c/clinical-agent-transformer-llama-31-8b"
98
+ hf_token = "YOUR_HF_TOKEN"
99
+
100
+ config = TrainingConfig(
101
+ model_name="meta-llama/Llama-3.1-8B-Instruct",
102
+ hf_cache_dir="./hf_cache",
103
+ adapter=AdapterConfig(
104
+ enabled=True,
105
+ adapter_name="clinical_agent_adapter",
106
+ r=8,
107
+ lora_alpha=32,
108
+ lora_dropout=0.05,
109
+ target_modules=("q_proj", "k_proj", "v_proj", "o_proj"),
110
+ ),
111
+ surgery=SurgeryConfig(
112
+ use_mla=True,
113
+ use_qk_norm=True,
114
+ use_post_norm=True,
115
+ use_moe_layers=True,
116
+ use_recurrent_layers=True,
117
+ use_mtp_head=True,
118
+ ),
119
+ )
120
+
121
+ tokenizer = load_tokenizer(config, hf_token)
122
+ model = load_model(config, hf_token)
123
+
124
+ state_path = hf_hub_download(repo_id=repo_id, filename="trainable_state.pt", token=hf_token)
125
+ state = torch.load(state_path, map_location="cpu")
126
+ model.load_state_dict(state, strict=False)
127
+
128
+ model = PeftModel.from_pretrained(model, repo_id, subfolder="model", token=hf_token)
129
+ model.eval()
130
+
131
+ prompt = "Evaluate ceftriaxone for community-acquired pneumonia in an adult with normal renal function."
132
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
133
+
134
+ with torch.no_grad():
135
+ output = model.generate(
136
+ **inputs,
137
+ max_new_tokens=256,
138
+ temperature=0.2,
139
+ do_sample=False,
140
+ )
141
+
142
+ print(tokenizer.decode(output[0], skip_special_tokens=True))
143
+ ```
144
+
145
+ ### Important Loading Note
146
+
147
+ The architecture surgery must be applied before loading `trainable_state.pt`. If someone loads only the adapter folder, they will miss the custom MLA, MoE, recurrent, post-norm, QK-Norm, and MTP trained components.
148
+
149
+ ## Training Artifacts
150
+
151
+ The metrics and graph files can be used to inspect the training behavior:
152
+
153
+ - `metrics.json`: final run metrics and architecture inspection.
154
+ - `training_history.csv`: train loss, validation loss, validation perplexity, and learning rate per recorded step.
155
+ - `train_validation_loss.png`: train/validation loss curve.
156
+ - `validation_perplexity.png`: validation perplexity curve.
157
+ - `learning_rate.png`: learning-rate schedule.
158
+
159
  ## Training Procedure
160
 
161
  The model was trained in two stages: