$ show drawthingsai/draw-things-community
This repository contains the public-facing source code for Draw Things, a production-grade AI image and video generation application for macOS/iOS/Linux. The codebase implements a comprehensive suite of diffusion models (Stable Diffusion, FLUX, HiDream, Qwen, MiniMax, etc.), samplers, LoRA training, model conversion, and a gRPC-based distributed inference server. It is written primarily in Swift, using Bazel for builds, and includes extensive use of FlatBuffers for data serialization, SQLite for persistence, and a custom neural network compiler (NNC) for on-device inference. The architecture is modular, with separate libraries for tokenization (CLIP, Tiktoken, SentencePiece), model zoos (downloadable model specifications), image generation pipelines, and cloud authentication. The repository also includes CLI tools (draw-things-cli, gRPCServerCLI, model converters) and server management scripts for deploying GPU-backed inference services with Tailscale, Envoy, and Docker. While the core application is a consumer-facing app, the codebase also contains research-grade components such as instruction count estimators for performance profiling, formal verification tools (Z3, Lean), and web search integration with browser fallback. The code is well-structured with many reusable patterns, though it carries some maintenance overhead from vendored dependencies and generated code.
The LLM identified 5 files worth highlighting for reuse:
Implements a robust, resumable file downloader with HEAD probe, SHA-256 integrity verification, .part file management, and segmented parallel download backend. The design is cleanly abstracted with pluggable backends (segmented and URLSession), making it reusable for any application needing reliable large-file downloads with resume capability.
Provides a memory-mapped reader for SafeTensors archive format, supporting FP8 (E4M3/E5M2) quantization. The implementation handles endianness, alignment, and nested tensor loading efficiently. This is a self-contained component that could be extracted for any project needing to read PyTorch-compatible weight files without Python dependencies.
A generic ordered set implementation with O(1) index-based access, append, remove, insert, and swap operations. It maintains both a list and a hash map internally for fast lookups while preserving insertion order. This is a well-crafted data structure that can be reused in any Swift project needing an ordered set with efficient random access.
Defines a flexible weight mapping system using closures that map checkpoint keys to model parameters with support for offsets, scales, interleaving, diagonal splitting, and affine transforms. The ModelWeightElement abstraction decouples model architecture from weight loading, enabling format conversion (SafeTensors, GGUF, etc.) and cross-architecture weight reuse. This pattern is central to the model import/export pipeline and is reusable for any neural network weight manipulation task.
Implements tiled diffusion inference for generating large images by splitting the latent space into overlapping tiles, processing each tile independently, and blending results with configurable weight functions. The implementation handles edge cases like non-divisible dimensions and provides a clean API for integrating with different model architectures. This is a reusable pattern for any diffusion-based image generation system that needs to produce high-resolution outputs beyond single-pass memory limits.