# keras-team/keras-hub architecture

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

- Interactive diagram: https://gitdiagram.com/keras-team/keras-hub
- Repository: https://github.com/keras-team/keras-hub

## Overview

KerasHub is a multi-backend pretrained-model library for text, image, audio, and multimodal tasks. The principal workflow is: a user calls the public Keras API, task models select preprocessing and tokenization, backbones execute shared modeling layers, and predictions or generated text are returned. Presets provide pretrained weights, while PipelineModel integrates preprocessing with Keras training/evaluation. The tree also documents metrics and an optional vLLM TPU serving path. Some subsystem links are inferred from documented APIs and filenames because most implementations were not sampled.

Main entry points: [`keras_hub/src/models/task.py`](https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/models/task.py) (Task Models), [`keras_hub/src/models/causal_lm.py`](https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/models/causal_lm.py) (Text Tasks), [`keras_hub/src/layers/preprocessing`](https://github.com/keras-team/keras-hub/tree/master/keras_hub/src/layers/preprocessing) (Media Preprocessing), [`keras_hub/api/__init__.py`](https://github.com/keras-team/keras-hub/blob/master/keras_hub/api/__init__.py) (KerasHub API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public API"]
  node_keras_api["KerasHub API<br/>[__init__.py]"]
end

subgraph group_input["Input Processing"]
  node_text_preprocessing["Text Preprocessing<br/>[preprocessor.py]"]
  node_tokenizers["Tokenizers"]
  node_media_preprocessing["Media Preprocessing"]
end

subgraph group_models["Model Runtime"]
  node_task_models["Task Models<br/>[task.py]"]
  node_text_tasks["Text Tasks<br/>[causal_lm.py]"]
  node_vision_tasks["Vision Tasks"]
  node_audio_tasks["Audio Tasks<br/>[audio_to_text.py]"]
  node_multimodal_tasks["Multimodal Tasks"]
  node_backbones["Model Backbones<br/>[backbone.py]"]
  node_transformer_layers["Transformer Layers"]
  node_rotary["Position Encoding"]
  node_preset_configs["Preset Configs<br/>[gemma_presets.py]"]
end

subgraph group_training["Training Evaluation"]
  node_pipeline["Pipeline Model<br/>[pipeline_model.py]"]
  node_metrics["Task Metrics<br/>[__init__.py]"]
end

subgraph group_serving["Serving Integrations"]
  node_vllm_wrapper["vLLM Wrapper"]
end

node_user(("Application User"))
node_kaggle_models["Kaggle Models"]
node_vllm["vLLM TPU"]
node_prediction["Predictions Results"]

node_user -->|"calls API"| node_keras_api
node_keras_api -->|"dispatches tasks"| node_task_models
node_task_models -->|"selects text"| node_text_tasks
node_task_models -->|"selects vision"| node_vision_tasks
node_task_models -->|"selects audio"| node_audio_tasks
node_task_models -->|"selects multimodal"| node_multimodal_tasks
node_text_tasks -->|"tokenizes text"| node_tokenizers
node_text_tasks -->|"preprocesses text"| node_text_preprocessing
node_vision_tasks -->|"preprocesses media"| node_media_preprocessing
node_audio_tasks -->|"preprocesses media"| node_media_preprocessing
node_multimodal_tasks -->|"preprocesses media"| node_media_preprocessing
node_task_models -->|"uses pipeline"| node_pipeline
node_pipeline -->|"applies preprocessing"| node_text_preprocessing
node_task_models -->|"runs backbone"| node_backbones
node_backbones -->|"executes layers"| node_transformer_layers
node_transformer_layers -->|"applies positions"| node_rotary
node_task_models -->|"loads presets"| node_preset_configs
node_preset_configs -.->|"fetches weights"| node_kaggle_models
node_user -->|"evaluates outputs"| node_metrics
node_vllm_wrapper -.->|"loads causal model"| node_text_tasks
node_vllm -.->|"invokes serving"| node_vllm_wrapper
node_task_models -->|"returns predictions"| node_prediction
node_text_tasks -->|"generates text"| node_prediction

click node_keras_api "https://github.com/keras-team/keras-hub/blob/master/keras_hub/api/__init__.py"
click node_task_models "https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/models/task.py"
click node_text_tasks "https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/models/causal_lm.py"
click node_vision_tasks "https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/models/image_classifier.py"
click node_audio_tasks "https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/models/audio_to_text.py"
click node_multimodal_tasks "https://github.com/keras-team/keras-hub/tree/master/keras_hub/src/models"
click node_text_preprocessing "https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/models/preprocessor.py"
click node_tokenizers "https://github.com/keras-team/keras-hub/tree/master/keras_hub/src/models"
click node_media_preprocessing "https://github.com/keras-team/keras-hub/tree/master/keras_hub/src/layers/preprocessing"
click node_backbones "https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/models/backbone.py"
click node_transformer_layers "https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/layers/modeling/transformer_decoder.py"
click node_rotary "https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/layers/modeling/rotary_embedding.py"
click node_pipeline "https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/utils/pipeline_model.py"
click node_metrics "https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/metrics/__init__.py"
click node_preset_configs "https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/models/gemma/gemma_presets.py"
click node_vllm_wrapper "https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/vllm/keras_hub_vllm_wrapper.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_keras_api,node_user toneBlue
class node_text_preprocessing,node_tokenizers,node_media_preprocessing toneAmber
class node_task_models,node_text_tasks,node_vision_tasks,node_audio_tasks,node_multimodal_tasks,node_backbones,node_transformer_layers,node_rotary,node_preset_configs toneMint
class node_pipeline,node_metrics toneRose
class node_vllm_wrapper,node_kaggle_models,node_vllm,node_prediction toneIndigo
```

## Components

### Public API

- [KerasHub API](https://github.com/keras-team/keras-hub/blob/master/keras_hub/api/__init__.py): `keras_hub/api/__init__.py`

### Input Processing

- [Text Preprocessing](https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/models/preprocessor.py): `keras_hub/src/models/preprocessor.py`
- [Tokenizers](https://github.com/keras-team/keras-hub/tree/master/keras_hub/src/models): `keras_hub/src/models`
- [Media Preprocessing](https://github.com/keras-team/keras-hub/tree/master/keras_hub/src/layers/preprocessing): `keras_hub/src/layers/preprocessing`

### Model Runtime

- [Task Models](https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/models/task.py): `keras_hub/src/models/task.py`
- [Text Tasks](https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/models/causal_lm.py): `keras_hub/src/models/causal_lm.py`
- [Vision Tasks](https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/models/image_classifier.py): `keras_hub/src/models/image_classifier.py`
- [Audio Tasks](https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/models/audio_to_text.py): `keras_hub/src/models/audio_to_text.py`
- [Multimodal Tasks](https://github.com/keras-team/keras-hub/tree/master/keras_hub/src/models): `keras_hub/src/models`
- [Model Backbones](https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/models/backbone.py): `keras_hub/src/models/backbone.py`
- [Transformer Layers](https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/layers/modeling/transformer_decoder.py): `keras_hub/src/layers/modeling/transformer_decoder.py`
- [Position Encoding](https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/layers/modeling/rotary_embedding.py): `keras_hub/src/layers/modeling/rotary_embedding.py`
- [Preset Configs](https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/models/gemma/gemma_presets.py): `keras_hub/src/models/gemma/gemma_presets.py`

### Training Evaluation

- [Pipeline Model](https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/utils/pipeline_model.py): `keras_hub/src/utils/pipeline_model.py`
- [Task Metrics](https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/metrics/__init__.py): `keras_hub/src/metrics/__init__.py`

### Serving Integrations

- [vLLM Wrapper](https://github.com/keras-team/keras-hub/blob/master/keras_hub/src/vllm/keras_hub_vllm_wrapper.py): `keras_hub/src/vllm/keras_hub_vllm_wrapper.py`

### Other components

- **Application User**
- **Kaggle Models**
- **vLLM TPU**
- **Predictions Results**

## Connections

- Application User → KerasHub API: calls API
- KerasHub API → Task Models: dispatches tasks
- Task Models → Text Tasks: selects text
- Task Models → Vision Tasks: selects vision
- Task Models → Audio Tasks: selects audio
- Task Models → Multimodal Tasks: selects multimodal
- Text Tasks → Tokenizers: tokenizes text
- Text Tasks → Text Preprocessing: preprocesses text
- Vision Tasks → Media Preprocessing: preprocesses media
- Audio Tasks → Media Preprocessing: preprocesses media
- Multimodal Tasks → Media Preprocessing: preprocesses media
- Task Models → Pipeline Model: uses pipeline
- Pipeline Model → Text Preprocessing: applies preprocessing
- Task Models → Model Backbones: runs backbone
- Model Backbones → Transformer Layers: executes layers
- Transformer Layers → Position Encoding: applies positions
- Task Models → Preset Configs: loads presets
- Preset Configs → Kaggle Models: fetches weights
- Application User → Task Metrics: evaluates outputs
- vLLM Wrapper → Text Tasks: loads causal model
- vLLM TPU → vLLM Wrapper: invokes serving
- Task Models → Predictions Results: returns predictions
- Text Tasks → Predictions Results: generates text
