File size: 13,823 Bytes
15d68eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f0c100
 
15d68eb
 
7f0c100
 
15d68eb
 
 
 
7f0c100
 
 
15d68eb
7f0c100
15d68eb
 
7f0c100
15d68eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f0c100
15d68eb
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# Indic Heritage Studio v2

**A multimodal content creation tool that reimagines modern photos and prompts through the lens of Indian heritage art forms β€” running on SDXL + Stable Video Diffusion + ControlNet + per-style LoRAs across 8 Γ— NVIDIA 80GB GPUs (dev) and AMD Radeon Cloud (final demo).**

> Submission for the **AMD AI DevMaster Hackathon (July 15 – August 6, 2026)**
> Track 1: Multimodal AI β€” Development of Multimodal Content Creation Tools
> Team: **TeamIndicForge**

---

## 🎯 What It Does (v2 β€” full rebuild)

Indic Heritage Studio v2 transforms everyday inputs into culturally-rooted visual art. Given a text prompt, a reference photo, or both, it produces:

1. **Text β†’ Heritage-styled image** β€” SDXL 1.0 (DreamShaper-XL turbo) at 1024Β² with per-style LoRA overlay
2. **Image β†’ Stylized image** β€” IP-Adapter XL on SDXL with optional multi-style blending (60% Madhubani + 40% Warli)
3. **Image β†’ 4-second video** β€” Stable Video Diffusion XT 1.1 (25 frames @ 8 fps, 1024Γ—576)
4. **ControlNet composition** β€” Canny / Depth / OpenPose conditioning for precise composition control
5. **Inpainting** β€” mask a region, restyle it in any heritage style (heritage restoration use case)
6. **Batch processing** β€” multi-GPU data parallelism across 4 worker GPUs (~4Γ— speedup)

Each output is styled after one of five authentic Indian art traditions, each with its own **fine-tuned LoRA** trained on real heritage art samples:
- 🟒 **Madhubani** β€” Bihar folk art, geometric patterns, natural pigments
- 🟀 **Warli** β€” Maharashtra tribal art, white-on-earth, stick figures
- πŸ”΅ **Pattachitra** β€” Odisha cloth painting, mythological narratives
- 🟑 **Mughal Miniature** β€” court painting, fine detail, gold leaf
- πŸ”΄ **Tanjore** β€” Tamil Nadu, gold-gilded devotional icons

An optional **AI Style Advisor** (powered by AMD's free Qwen API) helps users pick a style and refine prompts β€” but the **core generation runs 100% on AMD Radeon GPU** in compliance with Track 1 rules.

---

## πŸ†• What's New in v2

| Axis | v1 | v2 |
|---|---|---|
| T2I model | SD 1.5 (DreamShaper) | **SDXL 1.0 + DreamShaper-XL turbo** |
| Resolution | 512Γ—512 | **1024Γ—1024 (1536Β² for showcase)** |
| Style conditioning | Prompt tags only | **Per-style LoRA fine-tune + IP-Adapter XL** |
| Image β†’ video | AnimateDiff 16f | **Stable Video Diffusion XT 1.1, 25 frames** |
| Composition control | ❌ | **ControlNet (Canny/Depth/OpenPose)** |
| Image repair | ❌ | **SDXL inpainting** |
| Batch | Single GPU | **Multi-GPU data parallel, 4 workers** |
| Pipelines | Load/unload on demand | **All 4 resident on dedicated GPUs** |

---

## πŸ—οΈ System Architecture (Multi-GPU)

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       USER INTERFACE (Gradio)                    β”‚
β”‚  6 tabs + Style Advisor widget + GPU monitor sidebar            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              AGENT LAYER (free AMD Qwen/DeepSeek API)            β”‚
β”‚  StyleAdvisor Β· PromptEngineer Β· Critic                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                   β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        CORE GPU LAYER β€” MULTI-GPU (8 Γ— 80 GB dev)                β”‚
β”‚  GPU 0: SDXL T2I + Inpainting    GPU 4: Batch worker 0          β”‚
β”‚  GPU 1: SDXL + IP-Adapter XL     GPU 5: Batch worker 1          β”‚
β”‚  GPU 2: SVD-XT 1.1 (I2V)         GPU 6: Batch worker 2          β”‚
β”‚  GPU 3: SDXL + ControlNet        GPU 7: Batch worker 3          β”‚
β”‚  Per-style LoRAs (~150 MB each) loaded on demand                β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```

On AMD Radeon Cloud (single GPU), all pipelines share GPU 0 and load/unload on demand. The code auto-detects device count.

---

## πŸ› οΈ Tech Stack

| Layer | Tech |
|---|---|
| Dev hardware | 8 Γ— NVIDIA A100/H100 80GB (640 GB total VRAM) |
| Final demo hardware | AMD Radeon Cloud (Radeon GPU, ~16 GB VRAM) |
| Software stack | ROCm 6.2 (AMD) / CUDA 12.1 (NVIDIA dev) |
| Deep learning | PyTorch 2.4.1 + Diffusers 0.30 + Accelerate 0.34 + PEFT 0.12 |
| T2I model | SDXL 1.0 + DreamShaper-XL turbo |
| Style transfer | IP-Adapter XL (`h94/IP-Adapter`) |
| Image-to-video | Stable Video Diffusion XT 1.1 (`stabilityai/stable-video-diffusion-img2vid-xt-1-1`) |
| Composition control | ControlNet (Canny/Depth/OpenPose SDXL variants) |
| Per-style LoRAs | Trained with PEFT, rank 32, ~800 steps each |
| Agent LLM | Free AMD Model APIs (Qwen3.6-35B-A3B / DeepSeek-V4-Flash) |
| UI | Gradio 4.x |
| Video post | FFmpeg + OpenCV + imageio |
| Image post | Pillow, imageio |

---

## πŸ“¦ Installation

### Step 1 β€” Clone
```bash
git clone https://huggingface.co/Dev2506/indic-heritage-studio
cd indic-heritage-studio
```

# Setup
python -m venv .venv
source .venv/bin/activate
pip install torch==2.4.1 torchvision==0.19.1 --index-url https://download.pytorch.org/whl/cu121
pip install -r requirements.txt

# Configure
cp .env.example .env
# Edit .env to add AMD_MODEL_API_KEY (free at https://developer.amd.com.cn/radeon/modelapis)

# Launch
python app.py
# Open http://localhost:7860
\`\`\`

---

## πŸš€ Usage

### CLI mode

```bash
# Text-to-image in Madhubani style (SDXL + LoRA)
python -m core.text_to_image \
    --prompt "a young woman reading under a banyan tree" \
    --style madhubani \
    --out outputs/t2i_madhubani.png \
    --steps 25 --size 1024 --seed 42

# Style transfer (IP-Adapter XL)
python -m core.style_transfer \
    --image inputs/photo.jpg \
    --style warli \
    --out outputs/styled_warli.png \
    --strength 0.7 --ip-scale 0.7

# Image-to-video (SVD)
python -m core.image_to_video \
    --image outputs/styled_warli.png \
    --out outputs/warli_animated.mp4 \
    --frames 25 --fps 8

# ControlNet (Canny β†’ Mughal)
python -m core.controlnet \
    --condition-image inputs/sketch.png \
    --condition-type canny \
    --prompt "a courtly gathering" \
    --style mughal \
    --out outputs/controlnet_mughal.png

# Inpainting
python -m core.inpainting \
    --image inputs/damaged_painting.jpg \
    --mask inputs/damage_mask.png \
    --prompt "restore the floral border" \
    --style tanjore \
    --out outputs/restored.png

# Batch (multi-GPU, 4 workers)
python -m core.batch_processor \
    --mode style_transfer \
    --input-dir inputs/ \
    --output-dir outputs/batch/ \
    --workers 4
```

### Web UI

```bash
python app.py
```

The UI exposes all 6 modes plus the Style Advisor widget and GPU monitor.

---

## ⚑ Multi-GPU Optimization

The codebase applies these optimizations:

1. **Pipeline-to-GPU pinning** β€” T2I on GPU 0, IP-Adapter on GPU 1, SVD on GPU 2, ControlNet on GPU 3. No thrash.
2. **Batch data parallelism** β€” Inputs sharded across GPUs 4-7 via `multiprocessing.spawn`.
3. **Per-style LoRA hot-swap** β€” `unload_lora_weights` β†’ `load_lora_weights` in ~3 seconds (vs 30+ sec full pipeline reload).
4. **FP16 inference** β€” `torch_dtype=torch.float16` everywhere.
5. **SDPA attention** β€” built into PyTorch 2.0+, replaces xformers (CUDA-only).
6. **Attention + VAE slicing** β€” reduces VRAM peak ~30%.
7. **`torch.inference_mode()`** β€” all hot paths.
8. **Pipeline singleton reuse** β€” load once, serve many requests.

### Multi-GPU Benchmark

```bash
python scripts/benchmark.py --configs 1 2 4 8 --samples 4
```

Reports: latency per image, throughput (img/min), peak VRAM, scaling chart.

---

## πŸ“Š Evaluation Rubric Coverage

| Rubric item | Points | How v2 hits it |
|---|---|---|
| Complete input→processing→output workflow | 40 | 6 pipelines: T2I, I2I-style, I2V, ControlNet, Inpaint, batch |
| Innovative creation scenarios | 20 | Indian heritage art Γ— LoRA fine-tuning Γ— ControlNet Γ— SVD = unique vertical |
| Practical application & social value | 20 | Cultural preservation + heritage restoration + accessible creator tool |
| Clear, stable, diverse output on Radeon GPU | 20 | 6 output modes Γ— 5 art styles Γ— LoRA = 30+ high-quality demo outputs |

---

## πŸ—‚οΈ Project Structure

```
indic-heritage-studio-v2/
β”œβ”€β”€ README.md                       # This file
β”œβ”€β”€ app.py                          # Gradio UI entry point
β”œβ”€β”€ requirements.txt                # Python dependencies
β”œβ”€β”€ .env.example                    # Environment template
β”œβ”€β”€ .gitignore
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ settings.py                 # v2 global config (SDXL, multi-GPU, LoRA paths)
β”‚   └── styles.py                   # 5 heritage styles + LoRA scales + motion tuning
β”œβ”€β”€ agents/                         # LLM agent layer (free AMD API)
β”‚   β”œβ”€β”€ base.py
β”‚   β”œβ”€β”€ style_advisor.py
β”‚   β”œβ”€β”€ prompt_engineer.py          # SDXL-aware prompt enrichment
β”‚   └── critic.py                   # Heuristic + LLM critique
β”œβ”€β”€ core/                           # GPU layer
β”‚   β”œβ”€β”€ text_to_image.py            # SDXL + LoRA + optional refiner
β”‚   β”œβ”€β”€ style_transfer.py           # IP-Adapter XL + multi-style blending
β”‚   β”œβ”€β”€ image_to_video.py           # Stable Video Diffusion XT 1.1
β”‚   β”œβ”€β”€ controlnet.py               # Canny / Depth / OpenPose
β”‚   β”œβ”€β”€ inpainting.py               # SDXL inpainting + LoRA
β”‚   └── batch_processor.py          # Multi-GPU data parallel
β”œβ”€β”€ training/                       # NEW β€” LoRA training
β”‚   β”œβ”€β”€ prepare_dataset.py          # Heritage art dataset prep
β”‚   └── train_lora.py               # PEFT LoRA on SDXL UNet
β”œβ”€β”€ ui/
β”‚   └── gradio_app.py               # 6-tab web UI
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ gpu_utils.py                # Multi-GPU device management
β”‚   β”œβ”€β”€ image_utils.py
β”‚   └── video_utils.py
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ benchmark.py                # Multi-GPU scaling benchmark
β”‚   β”œβ”€β”€ download_models.py          # All v2 models (~35 GB)
β”‚   β”œβ”€β”€ generate_demo_outputs.py    # Pre-bake demo gallery
β”‚   β”œβ”€β”€ verify_rocm.py              # Env health check
β”‚   β”œβ”€β”€ day1_setup.sh               # Day 1 environment setup
β”‚   └── amd_demo_recording.sh       # AMD demo recording script
β”œβ”€β”€ assets/
β”‚   β”œβ”€β”€ styles/                     # IP-Adapter reference images (5)
β”‚   β”œβ”€β”€ datasets/                   # LoRA training datasets
β”‚   └── loras/                      # Trained LoRA weights (5 Γ— ~150 MB)
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ architecture.md             # Detailed v2 architecture
β”‚   β”œβ”€β”€ 2_week_plan.md              # Replan for 8Γ—80GB dev
β”‚   β”œβ”€β”€ local_dev_setup.md          # NVIDIA CUDA setup
β”‚   └── architecture_diagram.png
β”œβ”€β”€ examples/                       # Demo gallery (pre-baked)
└── tests/                          # Smoke tests
```

---

## πŸ“… Build Schedule (2-week plan)

See [`docs/2_week_plan.md`](docs/2_week_plan.md) for the day-by-day plan. Summary:

- **Week 1 (Jul 16–22):** Env setup, source heritage art datasets, train 5 LoRAs, smoke-test all 6 pipelines.
- **Week 2 (Jul 23–29):** Pre-bake demo gallery, run multi-GPU benchmark, write PDF + PPT, code freeze.
- **Week 3 (Jul 30–Aug 5):** AMD verification + demo recording + submit. Burns ~1.5 of 10 AMD credits.

---

## πŸ“ Submission Package

The 4 required deliverables (Track 1):

1. **Project Profile Document (PDF)** β€” generated via the `pdf` skill in Week 2
2. **Source Code (this repo)** β€” fork of `AMD-DEV-CONTEST/Radeon-hackathon-2026-07`
3. **Demo Video (3–5 min)** β€” `rocm-smi` β†’ CLI β†’ live GPU inference β†’ UI walkthrough
4. **PPT / Poster** β€” generated via the `pptx` skill in Week 2

PR title format: `Track 1, TeamIndicForge, Indic Heritage Studio`

---

## πŸ†˜ Troubleshooting

| Issue | Fix |
|---|---|
| `torch.cuda.is_available() == False` | Reinstall PyTorch with `--index-url https://download.pytorch.org/whl/cu121` |
| LoRA training OOMs | Lower `--rank` from 32 β†’ 16, or `--batch-size` from 1 β†’ 1 with `--grad-accum 8` |
| SVD OOM on AMD | Use `--frames 14` (instead of 25) |
| ControlNet preprocessor download fails | `python -c "from controlnet_aux import CannyDetector; CannyDetector.from_pretrained('lllyasviel/Annotators')"` |
| Multi-GPU batch fails to spawn | Set `MULTI_GPU=0` in `.env` |
| HuggingFace download slow | `HF_HUB_ENABLE_HF_TRANSFER=1` (already in `.env`) |
| Qwen API 429 errors | Agent layer is optional; core tool still works |

---

## πŸ“§ Contact

- **Hackathon email:** ai_dev_contests@amd.com
- **Discord:** https://discord.gg/zt9caur5B3
- **Team:** TeamIndicForg

---

## πŸ“œ License

MIT for project code. Model checkpoints retain their original licenses (see HuggingFace model cards).