# zzhustc2016/lamo architecture

> Architecture diagram of the GitHub repository zzhustc2016/lamo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zzhustc2016/lamo
- Repository: https://github.com/zzhustc2016/lamo

## Overview

This repository supports LLM-based medication recommendation from patient-visit data, including training drug-specific or grouped LoRA adapters and evaluating recommendations. The principal workflow is `finetune_each_drug.py`: it selects medicines, generates training examples, launches fine-tuning, evaluates each result, and renames the checkpoint. Separate evaluation scripts cover overall, per-drug, per-adapter, and grouped-adapter evaluation. Source excerpts establish several utility calls; the README is empty and some training and data-processing files were not sampled, so uncertain connections are omitted.

Main entry points: [`evaluation/_2_each_drug_evaluation_vllm.py`](https://github.com/zzhustc2016/lamo/blob/main/evaluation/_2_each_drug_evaluation_vllm.py) (Per-drug evaluation), [`evaluation/_3_each_lora_evaluation_vllm.py`](https://github.com/zzhustc2016/lamo/blob/main/evaluation/_3_each_lora_evaluation_vllm.py) (Per-adapter evaluation), [`evaluation/_1_overall_evaluation_vllm.py`](https://github.com/zzhustc2016/lamo/blob/main/evaluation/_1_overall_evaluation_vllm.py) (Overall evaluation), [`evaluation/_4_group_lora_evaluation_vllm.py`](https://github.com/zzhustc2016/lamo/blob/main/evaluation/_4_group_lora_evaluation_vllm.py) (Grouped-adapter evaluation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Clinical data"]
  node_visit_data[("Visit data")]
  node_note_processing["Note processing<br/>[utils.py]"]
  node_example_generation["Example generation"]
end

subgraph group_training["Adapter training"]
  node_training_orchestrator["Drug training"]
  node_general_training["General fine-tuning<br/>[finetune.py]"]
  node_fixed_training["Fixed-drug training"]
  node_group_training["Grouped-drug training"]
  node_checkpoints[("Adapter checkpoints")]
end

subgraph group_evaluation["Recommendation evaluation"]
  node_overall_eval["Overall evaluation"]
  node_drug_eval["Per-drug evaluation"]
  node_adapter_eval["Per-adapter evaluation"]
  node_group_eval["Grouped-adapter evaluation"]
  node_predictions[("Prediction results")]
  node_evaluation_metrics["Recommendation metrics<br/>[evaluate_utils.py]"]
end

subgraph group_runtime["Shared runtime"]
  node_data_loading["Data loading<br/>[file_utils.py]"]
  node_prompting["Prompt construction<br/>[prompt_utils.py]"]
  node_adapter_merge["Adapter merging"]
  node_model_loading["Model loading<br/>[model_utils.py]"]
end

node_operator(("Researcher"))
node_base_models[("Base models")]
node_openai(("OpenAI API"))

node_operator -->|"starts training"| node_training_orchestrator
node_training_orchestrator -->|"generates examples"| node_example_generation
node_example_generation -->|"loads visits"| node_data_loading
node_example_generation -->|"builds prompts"| node_prompting
node_training_orchestrator -->|"launches training"| node_fixed_training
node_training_orchestrator -->|"evaluates adapter"| node_drug_eval
node_training_orchestrator -->|"renames checkpoint"| node_checkpoints
node_note_processing -->|"summarizes notes"| node_openai
node_overall_eval -->|"loads test data"| node_data_loading
node_overall_eval -->|"constructs prompts"| node_prompting
node_overall_eval -->|"merges adapter"| node_adapter_merge
node_overall_eval -.->|"loads model"| node_model_loading
node_drug_eval -->|"loads test data"| node_data_loading
node_drug_eval -->|"constructs prompts"| node_prompting
node_drug_eval -->|"merges adapter"| node_adapter_merge
node_drug_eval -->|"loads model"| node_model_loading
node_drug_eval -.->|"stores predictions"| node_predictions
node_adapter_eval -.->|"loads test data"| node_data_loading
node_adapter_eval -->|"constructs prompts"| node_prompting
node_adapter_eval -->|"merges adapter"| node_adapter_merge
node_adapter_eval -->|"loads model"| node_model_loading
node_adapter_eval -->|"saves predictions"| node_predictions
node_group_eval -.->|"loads test data"| node_data_loading
node_group_eval -->|"constructs prompts"| node_prompting
node_group_eval -->|"merges adapter"| node_adapter_merge
node_group_eval -->|"loads model"| node_model_loading
node_overall_eval -.->|"scores results"| node_evaluation_metrics
node_drug_eval -.->|"scores results"| node_evaluation_metrics
node_adapter_eval -.->|"scores results"| node_evaluation_metrics
node_group_eval -.->|"scores results"| node_evaluation_metrics
node_general_training -.->|"loads base model"| node_base_models
node_fixed_training -.->|"loads base model"| node_base_models
node_group_training -.->|"loads base model"| node_base_models

click node_visit_data "https://github.com/zzhustc2016/lamo/tree/main/data"
click node_note_processing "https://github.com/zzhustc2016/lamo/blob/main/data/mimic-iii/utils.py"
click node_example_generation "https://github.com/zzhustc2016/lamo/blob/main/data/generate_finetune_data.py"
click node_training_orchestrator "https://github.com/zzhustc2016/lamo/blob/main/src/finetune_each_drug.py"
click node_general_training "https://github.com/zzhustc2016/lamo/blob/main/src/finetune.py"
click node_fixed_training "https://github.com/zzhustc2016/lamo/blob/main/src/finetune_fix_drug.py"
click node_group_training "https://github.com/zzhustc2016/lamo/blob/main/src/finetune_group_drug.py"
click node_checkpoints "https://github.com/zzhustc2016/lamo/tree/main/output"
click node_base_models "https://github.com/zzhustc2016/lamo/tree/main/Models"
click node_overall_eval "https://github.com/zzhustc2016/lamo/blob/main/evaluation/_1_overall_evaluation_vllm.py"
click node_drug_eval "https://github.com/zzhustc2016/lamo/blob/main/evaluation/_2_each_drug_evaluation_vllm.py"
click node_adapter_eval "https://github.com/zzhustc2016/lamo/blob/main/evaluation/_3_each_lora_evaluation_vllm.py"
click node_group_eval "https://github.com/zzhustc2016/lamo/blob/main/evaluation/_4_group_lora_evaluation_vllm.py"
click node_predictions "https://github.com/zzhustc2016/lamo/tree/main/output"
click node_evaluation_metrics "https://github.com/zzhustc2016/lamo/blob/main/utils/evaluate_utils.py"
click node_data_loading "https://github.com/zzhustc2016/lamo/blob/main/utils/file_utils.py"
click node_prompting "https://github.com/zzhustc2016/lamo/blob/main/utils/prompt_utils.py"
click node_adapter_merge "https://github.com/zzhustc2016/lamo/blob/main/utils/merge_lora_utils.py"
click node_model_loading "https://github.com/zzhustc2016/lamo/blob/main/utils/model_utils.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_visit_data,node_note_processing,node_example_generation toneBlue
class node_training_orchestrator,node_general_training,node_fixed_training,node_group_training,node_checkpoints,node_base_models toneAmber
class node_overall_eval,node_drug_eval,node_adapter_eval,node_group_eval,node_predictions,node_evaluation_metrics,node_openai toneMint
class node_data_loading,node_prompting,node_adapter_merge,node_model_loading toneRose
class node_operator toneIndigo
```

## Components

### Clinical data

- [Visit data](https://github.com/zzhustc2016/lamo/tree/main/data): `data`
- [Note processing](https://github.com/zzhustc2016/lamo/blob/main/data/mimic-iii/utils.py): `data/mimic-iii/utils.py`
- [Example generation](https://github.com/zzhustc2016/lamo/blob/main/data/generate_finetune_data.py): `data/generate_finetune_data.py`

### Adapter training

- [Drug training](https://github.com/zzhustc2016/lamo/blob/main/src/finetune_each_drug.py): `src/finetune_each_drug.py`
- [General fine-tuning](https://github.com/zzhustc2016/lamo/blob/main/src/finetune.py): `src/finetune.py`
- [Fixed-drug training](https://github.com/zzhustc2016/lamo/blob/main/src/finetune_fix_drug.py): `src/finetune_fix_drug.py`
- [Grouped-drug training](https://github.com/zzhustc2016/lamo/blob/main/src/finetune_group_drug.py): `src/finetune_group_drug.py`
- [Adapter checkpoints](https://github.com/zzhustc2016/lamo/tree/main/output): `output`

### Recommendation evaluation

- [Overall evaluation](https://github.com/zzhustc2016/lamo/blob/main/evaluation/_1_overall_evaluation_vllm.py): `evaluation/_1_overall_evaluation_vllm.py`
- [Per-drug evaluation](https://github.com/zzhustc2016/lamo/blob/main/evaluation/_2_each_drug_evaluation_vllm.py): `evaluation/_2_each_drug_evaluation_vllm.py`
- [Per-adapter evaluation](https://github.com/zzhustc2016/lamo/blob/main/evaluation/_3_each_lora_evaluation_vllm.py): `evaluation/_3_each_lora_evaluation_vllm.py`
- [Grouped-adapter evaluation](https://github.com/zzhustc2016/lamo/blob/main/evaluation/_4_group_lora_evaluation_vllm.py): `evaluation/_4_group_lora_evaluation_vllm.py`
- [Prediction results](https://github.com/zzhustc2016/lamo/tree/main/output): `output`
- [Recommendation metrics](https://github.com/zzhustc2016/lamo/blob/main/utils/evaluate_utils.py): `utils/evaluate_utils.py`

### Shared runtime

- [Data loading](https://github.com/zzhustc2016/lamo/blob/main/utils/file_utils.py): `utils/file_utils.py`
- [Prompt construction](https://github.com/zzhustc2016/lamo/blob/main/utils/prompt_utils.py): `utils/prompt_utils.py`
- [Adapter merging](https://github.com/zzhustc2016/lamo/blob/main/utils/merge_lora_utils.py): `utils/merge_lora_utils.py`
- [Model loading](https://github.com/zzhustc2016/lamo/blob/main/utils/model_utils.py): `utils/model_utils.py`

### Other components

- **Researcher**
- [Base models](https://github.com/zzhustc2016/lamo/tree/main/Models): `Models`
- **OpenAI API**

## Connections

- Researcher → Drug training: starts training (evidence: `src/finetune_each_drug.py`)
- Drug training → Example generation: generates examples (evidence: `src/finetune_each_drug.py`)
- Example generation → Data loading: loads visits (evidence: `data/generate_finetune_data.py`)
- Example generation → Prompt construction: builds prompts (evidence: `data/generate_finetune_data.py`)
- Drug training → Fixed-drug training: launches training (evidence: `src/finetune_each_drug.py`)
- Drug training → Per-drug evaluation: evaluates adapter (evidence: `src/finetune_each_drug.py`)
- Drug training → Adapter checkpoints: renames checkpoint (evidence: `src/finetune_each_drug.py`)
- Note processing → OpenAI API: summarizes notes (evidence: `data/mimic-iii/utils.py`)
- Overall evaluation → Data loading: loads test data (evidence: `evaluation/_1_overall_evaluation_vllm.py`)
- Overall evaluation → Prompt construction: constructs prompts (evidence: `evaluation/_1_overall_evaluation_vllm.py`)
- Overall evaluation → Adapter merging: merges adapter (evidence: `evaluation/_1_overall_evaluation_vllm.py`)
- Overall evaluation → Model loading: loads model
- Per-drug evaluation → Data loading: loads test data (evidence: `evaluation/_2_each_drug_evaluation_vllm.py`)
- Per-drug evaluation → Prompt construction: constructs prompts (evidence: `evaluation/_2_each_drug_evaluation_vllm.py`)
- Per-drug evaluation → Adapter merging: merges adapter (evidence: `evaluation/_2_each_drug_evaluation_vllm.py`)
- Per-drug evaluation → Model loading: loads model (evidence: `evaluation/_2_each_drug_evaluation_vllm.py`)
- Per-drug evaluation → Prediction results: stores predictions
- Per-adapter evaluation → Data loading: loads test data
- Per-adapter evaluation → Prompt construction: constructs prompts (evidence: `evaluation/_3_each_lora_evaluation_vllm.py`)
- Per-adapter evaluation → Adapter merging: merges adapter (evidence: `evaluation/_3_each_lora_evaluation_vllm.py`)
- Per-adapter evaluation → Model loading: loads model (evidence: `evaluation/_3_each_lora_evaluation_vllm.py`)
- Per-adapter evaluation → Prediction results: saves predictions (evidence: `evaluation/_3_each_lora_evaluation_vllm.py`)
- Grouped-adapter evaluation → Data loading: loads test data
- Grouped-adapter evaluation → Prompt construction: constructs prompts (evidence: `evaluation/_4_group_lora_evaluation_vllm.py`)
- Grouped-adapter evaluation → Adapter merging: merges adapter (evidence: `evaluation/_4_group_lora_evaluation_vllm.py`)
- Grouped-adapter evaluation → Model loading: loads model (evidence: `evaluation/_4_group_lora_evaluation_vllm.py`)
- Overall evaluation → Recommendation metrics: scores results
- Per-drug evaluation → Recommendation metrics: scores results
- Per-adapter evaluation → Recommendation metrics: scores results
- Grouped-adapter evaluation → Recommendation metrics: scores results
- General fine-tuning → Base models: loads base model
- Fixed-drug training → Base models: loads base model
- Grouped-drug training → Base models: loads base model
