# vv176/week1_ai_engineering architecture

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

- Interactive diagram: https://gitdiagram.com/vv176/week1_ai_engineering
- Repository: https://github.com/vv176/week1_ai_engineering

## Overview

This repository is a collection of standalone AI-engineering teaching scripts, not one integrated application. Its lessons cover model behavior and generation, API-based techniques, and application patterns such as structured output, streaming, and concurrency. There is no documented end-to-end workflow, so the graph preserves these as separate learning branches rather than implying a runtime pipeline. External model-service calls are shown only where sampled source demonstrates them; several unsampled lessons are represented by their exact enclosing directories.

Main entry points: [`streaming_demo`](https://github.com/vv176/week1_ai_engineering/tree/main/streaming_demo) (Streaming Demos), [`GPT2_workflow.py`](https://github.com/vv176/week1_ai_engineering/blob/main/GPT2_workflow.py) (GPT-2 Workflow), [`pretraining_sft_rlhf/03_rlhf_preference.py`](https://github.com/vv176/week1_ai_engineering/blob/main/pretraining_sft_rlhf/03_rlhf_preference.py) (RLHF Preferences), [`sampling_deep_dive/02_topk_topp_minp.py`](https://github.com/vv176/week1_ai_engineering/blob/main/sampling_deep_dive/02_topk_topp_minp.py) (Sampling Filters)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_model["Model Fundamentals"]
  node_workflow["GPT-2 Workflow<br/>[GPT2_workflow.py]"]
  node_tokenizer["Tokenization<br/>[tokenizer.py]"]
  node_vocab["Vocabulary Printing"]
  node_embeddings["Embedding Visualization<br/>[basic_embedding.py]"]
  node_pretrain["Base Model<br/>[01_base_model.py]"]
  node_sft["SFT Effects<br/>[02_sft_effect.py]"]
  node_rlhf["RLHF Preferences"]
  node_temperature["Temperature Sampling"]
  node_filters["Sampling Filters"]
  node_creativity["Deterministic vs Creative"]
end

subgraph group_api["LLM API Patterns"]
  node_token_embeds["Token Embeddings API"]
  node_logprob_raw["Raw Logprobs<br/>[01_raw_logprobs.py]"]
  node_confidence["Confidence Scoring"]
  node_classification["Logprob Classification"]
end

subgraph group_apps["Application Patterns"]
  node_structured["Structured Outputs"]
  node_streaming["Streaming Demos"]
  node_generators["Yield and Generators"]
end

subgraph group_concurrency["Concurrency Lessons"]
  node_thread_basics["Threading Basics"]
  node_parallel_llm["Parallel LLM Calls"]
  node_parallel_tools["Parallel Tool Calls"]
  node_rag["Parallel RAG Search"]
  node_stream_threads["Streaming with Threads"]
end

node_learner(("Learner"))
node_openai{{"OpenAI API"}}
node_hf{{"Hugging Face GPT-2"}}

node_learner -->|"runs lesson"| node_workflow
node_learner -->|"runs lesson"| node_tokenizer
node_learner -->|"runs lesson"| node_vocab
node_learner -->|"runs lesson"| node_embeddings
node_learner -->|"runs lesson"| node_token_embeds
node_learner -->|"runs lesson"| node_logprob_raw
node_learner -->|"runs lesson"| node_confidence
node_learner -->|"runs lesson"| node_classification
node_learner -->|"runs lesson"| node_pretrain
node_learner -->|"runs lesson"| node_sft
node_learner -->|"runs lesson"| node_rlhf
node_learner -->|"runs lesson"| node_temperature
node_learner -->|"runs lesson"| node_filters
node_learner -->|"runs lesson"| node_creativity
node_learner -->|"runs lesson"| node_structured
node_learner -->|"runs lesson"| node_streaming
node_learner -->|"runs lesson"| node_generators
node_learner -->|"runs lesson"| node_thread_basics
node_learner -->|"runs lesson"| node_parallel_llm
node_learner -->|"runs lesson"| node_parallel_tools
node_learner -->|"runs lesson"| node_rag
node_learner -->|"runs lesson"| node_stream_threads
node_workflow -.->|"loads model"| node_hf
node_filters -->|"loads GPT-2"| node_hf
node_token_embeds -->|"requests embeddings"| node_openai
node_classification -->|"requests completion"| node_openai
node_rlhf -->|"requests completion"| node_openai
node_structured -->|"requests completion"| node_openai
node_parallel_llm -->|"requests completion"| node_openai
node_streaming -->|"streams completion"| node_openai
node_streaming -->|"requests completion"| node_openai

click node_workflow "https://github.com/vv176/week1_ai_engineering/blob/main/GPT2_workflow.py"
click node_tokenizer "https://github.com/vv176/week1_ai_engineering/blob/main/tokenizer.py"
click node_vocab "https://github.com/vv176/week1_ai_engineering/blob/main/vocabulary_printing.py"
click node_embeddings "https://github.com/vv176/week1_ai_engineering/blob/main/basic_embedding.py"
click node_token_embeds "https://github.com/vv176/week1_ai_engineering/blob/main/token_embeddings_api_call.py"
click node_logprob_raw "https://github.com/vv176/week1_ai_engineering/blob/main/logprobs/01_raw_logprobs.py"
click node_confidence "https://github.com/vv176/week1_ai_engineering/blob/main/logprobs/02_confidence_scoring.py"
click node_classification "https://github.com/vv176/week1_ai_engineering/blob/main/logprobs/03_classification_free.py"
click node_pretrain "https://github.com/vv176/week1_ai_engineering/blob/main/pretraining_sft_rlhf/01_base_model.py"
click node_sft "https://github.com/vv176/week1_ai_engineering/blob/main/pretraining_sft_rlhf/02_sft_effect.py"
click node_rlhf "https://github.com/vv176/week1_ai_engineering/blob/main/pretraining_sft_rlhf/03_rlhf_preference.py"
click node_temperature "https://github.com/vv176/week1_ai_engineering/blob/main/sampling_deep_dive/01_temperature_visualization.py"
click node_filters "https://github.com/vv176/week1_ai_engineering/blob/main/sampling_deep_dive/02_topk_topp_minp.py"
click node_creativity "https://github.com/vv176/week1_ai_engineering/blob/main/sampling_deep_dive/03_deterministic_vs_creative.py"
click node_structured "https://github.com/vv176/week1_ai_engineering/tree/main/structured_outputs"
click node_streaming "https://github.com/vv176/week1_ai_engineering/tree/main/streaming_demo"
click node_generators "https://github.com/vv176/week1_ai_engineering/tree/main/streaming_demo/yields"
click node_thread_basics "https://github.com/vv176/week1_ai_engineering/tree/main/threading_demo"
click node_parallel_llm "https://github.com/vv176/week1_ai_engineering/blob/main/threading_demo/08_parallel_llm_calls.py"
click node_parallel_tools "https://github.com/vv176/week1_ai_engineering/blob/main/threading_demo/09_parallel_tool_calls.py"
click node_rag "https://github.com/vv176/week1_ai_engineering/blob/main/threading_demo/10_divide_and_conquer_rag.py"
click node_stream_threads "https://github.com/vv176/week1_ai_engineering/blob/main/threading_demo/11_streaming_plus_threading.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_workflow,node_tokenizer,node_vocab,node_embeddings,node_pretrain,node_sft,node_rlhf,node_temperature,node_filters,node_creativity toneBlue
class node_token_embeds,node_logprob_raw,node_confidence,node_classification toneAmber
class node_structured,node_streaming,node_generators,node_openai toneMint
class node_thread_basics,node_parallel_llm,node_parallel_tools,node_rag,node_stream_threads toneRose
class node_learner,node_hf toneIndigo
```

## Components

### Model Fundamentals

- [GPT-2 Workflow](https://github.com/vv176/week1_ai_engineering/blob/main/GPT2_workflow.py): `GPT2_workflow.py`
- [Tokenization](https://github.com/vv176/week1_ai_engineering/blob/main/tokenizer.py): `tokenizer.py`
- [Vocabulary Printing](https://github.com/vv176/week1_ai_engineering/blob/main/vocabulary_printing.py): `vocabulary_printing.py`
- [Embedding Visualization](https://github.com/vv176/week1_ai_engineering/blob/main/basic_embedding.py): `basic_embedding.py`
- [Base Model](https://github.com/vv176/week1_ai_engineering/blob/main/pretraining_sft_rlhf/01_base_model.py): `pretraining_sft_rlhf/01_base_model.py`
- [SFT Effects](https://github.com/vv176/week1_ai_engineering/blob/main/pretraining_sft_rlhf/02_sft_effect.py): `pretraining_sft_rlhf/02_sft_effect.py`
- [RLHF Preferences](https://github.com/vv176/week1_ai_engineering/blob/main/pretraining_sft_rlhf/03_rlhf_preference.py): `pretraining_sft_rlhf/03_rlhf_preference.py`
- [Temperature Sampling](https://github.com/vv176/week1_ai_engineering/blob/main/sampling_deep_dive/01_temperature_visualization.py): `sampling_deep_dive/01_temperature_visualization.py`
- [Sampling Filters](https://github.com/vv176/week1_ai_engineering/blob/main/sampling_deep_dive/02_topk_topp_minp.py): `sampling_deep_dive/02_topk_topp_minp.py`
- [Deterministic vs Creative](https://github.com/vv176/week1_ai_engineering/blob/main/sampling_deep_dive/03_deterministic_vs_creative.py): `sampling_deep_dive/03_deterministic_vs_creative.py`

### LLM API Patterns

- [Token Embeddings API](https://github.com/vv176/week1_ai_engineering/blob/main/token_embeddings_api_call.py): `token_embeddings_api_call.py`
- [Raw Logprobs](https://github.com/vv176/week1_ai_engineering/blob/main/logprobs/01_raw_logprobs.py): `logprobs/01_raw_logprobs.py`
- [Confidence Scoring](https://github.com/vv176/week1_ai_engineering/blob/main/logprobs/02_confidence_scoring.py): `logprobs/02_confidence_scoring.py`
- [Logprob Classification](https://github.com/vv176/week1_ai_engineering/blob/main/logprobs/03_classification_free.py): `logprobs/03_classification_free.py`

### Application Patterns

- [Structured Outputs](https://github.com/vv176/week1_ai_engineering/tree/main/structured_outputs): `structured_outputs`
- [Streaming Demos](https://github.com/vv176/week1_ai_engineering/tree/main/streaming_demo): `streaming_demo`
- [Yield and Generators](https://github.com/vv176/week1_ai_engineering/tree/main/streaming_demo/yields): `streaming_demo/yields`

### Concurrency Lessons

- [Threading Basics](https://github.com/vv176/week1_ai_engineering/tree/main/threading_demo): `threading_demo`
- [Parallel LLM Calls](https://github.com/vv176/week1_ai_engineering/blob/main/threading_demo/08_parallel_llm_calls.py): `threading_demo/08_parallel_llm_calls.py`
- [Parallel Tool Calls](https://github.com/vv176/week1_ai_engineering/blob/main/threading_demo/09_parallel_tool_calls.py): `threading_demo/09_parallel_tool_calls.py`
- [Parallel RAG Search](https://github.com/vv176/week1_ai_engineering/blob/main/threading_demo/10_divide_and_conquer_rag.py): `threading_demo/10_divide_and_conquer_rag.py`
- [Streaming with Threads](https://github.com/vv176/week1_ai_engineering/blob/main/threading_demo/11_streaming_plus_threading.py): `threading_demo/11_streaming_plus_threading.py`

### Other components

- **Learner**
- **OpenAI API**
- **Hugging Face GPT-2**

## Connections

- Learner → GPT-2 Workflow: runs lesson (evidence: `GPT2_workflow.py`)
- Learner → Tokenization: runs lesson (evidence: `tokenizer.py`)
- Learner → Vocabulary Printing: runs lesson (evidence: `vocabulary_printing.py`)
- Learner → Embedding Visualization: runs lesson (evidence: `basic_embedding.py`)
- Learner → Token Embeddings API: runs lesson (evidence: `token_embeddings_api_call.py`)
- Learner → Raw Logprobs: runs lesson (evidence: `logprobs/01_raw_logprobs.py`)
- Learner → Confidence Scoring: runs lesson (evidence: `logprobs/02_confidence_scoring.py`)
- Learner → Logprob Classification: runs lesson (evidence: `logprobs/03_classification_free.py`)
- Learner → Base Model: runs lesson (evidence: `pretraining_sft_rlhf/01_base_model.py`)
- Learner → SFT Effects: runs lesson (evidence: `pretraining_sft_rlhf/02_sft_effect.py`)
- Learner → RLHF Preferences: runs lesson (evidence: `pretraining_sft_rlhf/03_rlhf_preference.py`)
- Learner → Temperature Sampling: runs lesson (evidence: `sampling_deep_dive/01_temperature_visualization.py`)
- Learner → Sampling Filters: runs lesson (evidence: `sampling_deep_dive/02_topk_topp_minp.py`)
- Learner → Deterministic vs Creative: runs lesson (evidence: `sampling_deep_dive/03_deterministic_vs_creative.py`)
- Learner → Structured Outputs: runs lesson (evidence: `structured_outputs/01_naive_approach.py`)
- Learner → Streaming Demos: runs lesson (evidence: `streaming_demo/client_sse.py`)
- Learner → Yield and Generators: runs lesson (evidence: `streaming_demo/yields/06_file_processing.py`)
- Learner → Threading Basics: runs lesson (evidence: `threading_demo/03_thread_pool.py`)
- Learner → Parallel LLM Calls: runs lesson (evidence: `threading_demo/08_parallel_llm_calls.py`)
- Learner → Parallel Tool Calls: runs lesson (evidence: `threading_demo/09_parallel_tool_calls.py`)
- Learner → Parallel RAG Search: runs lesson (evidence: `threading_demo/10_divide_and_conquer_rag.py`)
- Learner → Streaming with Threads: runs lesson (evidence: `threading_demo/11_streaming_plus_threading.py`)
- GPT-2 Workflow → Hugging Face GPT-2: loads model
- Sampling Filters → Hugging Face GPT-2: loads GPT-2 (evidence: `sampling_deep_dive/02_topk_topp_minp.py`)
- Token Embeddings API → OpenAI API: requests embeddings (evidence: `token_embeddings_api_call.py`)
- Logprob Classification → OpenAI API: requests completion (evidence: `logprobs/03_classification_free.py`)
- RLHF Preferences → OpenAI API: requests completion (evidence: `pretraining_sft_rlhf/03_rlhf_preference.py`)
- Structured Outputs → OpenAI API: requests completion (evidence: `structured_outputs/01_naive_approach.py`)
- Parallel LLM Calls → OpenAI API: requests completion (evidence: `threading_demo/08_parallel_llm_calls.py`)
- Streaming Demos → OpenAI API: streams completion (evidence: `streaming_demo/client_openai_stream.py`)
- Streaming Demos → OpenAI API: requests completion (evidence: `streaming_demo/client_openai_normal.py`)
