# large-scale-sustainable-computing-lsc/green-code architecture

> Architecture diagram of the GitHub repository large-scale-sustainable-computing-lsc/green-code, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/large-scale-sustainable-computing-lsc/green-code
- Repository: https://github.com/large-scale-sustainable-computing-lsc/green-code

## Overview

GREEN-CODE trains early-exit language models and RL policies offline, then serves energy-aware code completion online. The graph preserves dataset preparation, fine-tuning, RL training, evaluation, and analysis as distinct stages. Endpoint and model excerpts support the runtime links; several training and evaluation details come from the README, so uncertain implementation-level wiring is omitted.

Main entry points: [`src/models/llama/modeling_llama_rl_with_cache.py`](https://github.com/large-scale-sustainable-computing-lsc/green-code/blob/main/src/models/llama/modeling_llama_rl_with_cache.py) (Llama early-exit), [`src/models/opt/modeling_opt_ee_rl.py`](https://github.com/large-scale-sustainable-computing-lsc/green-code/blob/main/src/models/opt/modeling_opt_ee_rl.py) (OPT early-exit), [`src/eval/evaluator.py`](https://github.com/large-scale-sustainable-computing-lsc/green-code/blob/main/src/eval/evaluator.py) (Benchmark evaluation), [`src/models/rl`](https://github.com/large-scale-sustainable-computing-lsc/green-code/tree/main/src/models/rl) (RL agent training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_offline["Offline preparation"]
  node_dataset_viz["Dataset analysis<br/>[dataset_vis.py]"]
end

subgraph group_training["Model and policy training"]
  node_finetuner["Fine-tuning<br/>[finetuner.py]"]
  node_llama["Llama early-exit"]
  node_opt["OPT early-exit"]
  node_rl_env["RL environments"]
  node_rl_policy["RL agent training"]
end

subgraph group_runtime["Online generation"]
  node_endpoint["Generation API<br/>[main.py]"]
  node_generator["Generation adapter<br/>[generators.py]"]
end

subgraph group_assessment["Evaluation and analysis"]
  node_evaluator["Benchmark evaluation<br/>[evaluator.py]"]
  node_eval_tools["Specialized metrics"]
  node_plotter["Result visualization"]
end

node_engineer(("Engineer"))
node_code_data[("Code datasets")]
node_vscode(("VS Code client"))

node_engineer -->|"selects"| node_code_data
node_code_data -->|"analyzes"| node_dataset_viz
node_code_data -->|"loads and prepares"| node_finetuner
node_finetuner -->|"fine-tunes"| node_llama
node_finetuner -->|"fine-tunes"| node_opt
node_rl_env -->|"samples states"| node_llama
node_rl_env -->|"samples states"| node_opt
node_rl_policy -->|"trains in"| node_rl_env
node_rl_policy -->|"provides policy"| node_llama
node_rl_policy -->|"provides policy"| node_opt
node_vscode -->|"requests completion"| node_endpoint
node_endpoint -->|"dispatches request"| node_generator
node_generator -->|"generates with"| node_llama
node_endpoint -->|"updates threshold"| node_generator
node_code_data -->|"supplies samples"| node_evaluator
node_llama -->|"evaluated by"| node_evaluator
node_opt -->|"evaluated by"| node_evaluator
node_evaluator -->|"supports analysis"| node_eval_tools
node_eval_tools -->|"visualizes results"| node_plotter

click node_dataset_viz "https://github.com/large-scale-sustainable-computing-lsc/green-code/blob/main/src/datasets/dataset_vis.py"
click node_finetuner "https://github.com/large-scale-sustainable-computing-lsc/green-code/blob/main/src/train/finetuner.py"
click node_llama "https://github.com/large-scale-sustainable-computing-lsc/green-code/blob/main/src/models/llama/modeling_llama_rl_with_cache.py"
click node_opt "https://github.com/large-scale-sustainable-computing-lsc/green-code/blob/main/src/models/opt/modeling_opt_ee_rl.py"
click node_rl_env "https://github.com/large-scale-sustainable-computing-lsc/green-code/tree/main/src/models/rl/enviornments"
click node_rl_policy "https://github.com/large-scale-sustainable-computing-lsc/green-code/tree/main/src/models/rl"
click node_endpoint "https://github.com/large-scale-sustainable-computing-lsc/green-code/blob/main/src/endpoint/main.py"
click node_generator "https://github.com/large-scale-sustainable-computing-lsc/green-code/blob/main/src/endpoint/generators.py"
click node_evaluator "https://github.com/large-scale-sustainable-computing-lsc/green-code/blob/main/src/eval/evaluator.py"
click node_eval_tools "https://github.com/large-scale-sustainable-computing-lsc/green-code/tree/main/src/eval"
click node_plotter "https://github.com/large-scale-sustainable-computing-lsc/green-code/tree/main/src/plotter"

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_dataset_viz,node_vscode toneBlue
class node_finetuner,node_llama,node_opt,node_rl_env,node_rl_policy,node_code_data toneAmber
class node_endpoint,node_generator toneMint
class node_evaluator,node_eval_tools,node_plotter toneRose
class node_engineer toneIndigo
```

## Components

### Offline preparation

- [Dataset analysis](https://github.com/large-scale-sustainable-computing-lsc/green-code/blob/main/src/datasets/dataset_vis.py): `src/datasets/dataset_vis.py`

### Model and policy training

- [Fine-tuning](https://github.com/large-scale-sustainable-computing-lsc/green-code/blob/main/src/train/finetuner.py): `src/train/finetuner.py`
- [Llama early-exit](https://github.com/large-scale-sustainable-computing-lsc/green-code/blob/main/src/models/llama/modeling_llama_rl_with_cache.py): `src/models/llama/modeling_llama_rl_with_cache.py`
- [OPT early-exit](https://github.com/large-scale-sustainable-computing-lsc/green-code/blob/main/src/models/opt/modeling_opt_ee_rl.py): `src/models/opt/modeling_opt_ee_rl.py`
- [RL environments](https://github.com/large-scale-sustainable-computing-lsc/green-code/tree/main/src/models/rl/enviornments): `src/models/rl/enviornments`
- [RL agent training](https://github.com/large-scale-sustainable-computing-lsc/green-code/tree/main/src/models/rl): `src/models/rl`

### Online generation

- [Generation API](https://github.com/large-scale-sustainable-computing-lsc/green-code/blob/main/src/endpoint/main.py): `src/endpoint/main.py`
- [Generation adapter](https://github.com/large-scale-sustainable-computing-lsc/green-code/blob/main/src/endpoint/generators.py): `src/endpoint/generators.py`

### Evaluation and analysis

- [Benchmark evaluation](https://github.com/large-scale-sustainable-computing-lsc/green-code/blob/main/src/eval/evaluator.py): `src/eval/evaluator.py`
- [Specialized metrics](https://github.com/large-scale-sustainable-computing-lsc/green-code/tree/main/src/eval): `src/eval`
- [Result visualization](https://github.com/large-scale-sustainable-computing-lsc/green-code/tree/main/src/plotter): `src/plotter`

### Other components

- **Engineer**
- **Code datasets**
- **VS Code client**

## Connections

- Engineer → Code datasets: selects
- Code datasets → Dataset analysis: analyzes
- Code datasets → Fine-tuning: loads and prepares
- Fine-tuning → Llama early-exit: fine-tunes
- Fine-tuning → OPT early-exit: fine-tunes
- RL environments → Llama early-exit: samples states
- RL environments → OPT early-exit: samples states
- RL agent training → RL environments: trains in
- RL agent training → Llama early-exit: provides policy
- RL agent training → OPT early-exit: provides policy
- VS Code client → Generation API: requests completion
- Generation API → Generation adapter: dispatches request
- Generation adapter → Llama early-exit: generates with
- Generation API → Generation adapter: updates threshold
- Code datasets → Benchmark evaluation: supplies samples
- Llama early-exit → Benchmark evaluation: evaluated by
- OPT early-exit → Benchmark evaluation: evaluated by
- Benchmark evaluation → Specialized metrics: supports analysis
- Specialized metrics → Result visualization: visualizes results
