Hugging Face AI Engineer Interview Questions
Short answers to 11 AI engineering questions asked at Hugging Face.
Questions and answers (11)
Answers are written in plain English and reviewed for technical accuracy. Each answer states the point first, then the reason.
1. `transformers` famously repeats code: each model gets its own self-contained modeling file. Defend that decision, then critique it.
Each model file stays self-contained so that one model works without shared code. A reader can open one file and see the full forward pass. The cost is heavy duplication. A fix in one model often needs the same fix in many files, and review becomes slow.
2. Why did Hugging Face create safetensors when pickle-based checkpoints already worked everywhere?
Pickle checkpoints run arbitrary code when you load them. Safetensors stores only tensors and a small JSON header. The loader reads the header first and maps tensors without running code. It also loads faster because it avoids a full copy.
3. A user loads a 2 TB dataset with `datasets` on a 64 GB RAM machine and it works. How? And when does it stop working?
The datasets library memory-maps the files and reads rows on demand. It keeps an index and a small cache, not the full data. It stops working when a step needs the whole column in RAM. Examples are a full sort, a global shuffle, or a groupby over all rows.
4. Walk me through what actually happens when someone calls AutoModelForCausalLM.from_pretrained(…, device_map=“auto”, torch_dtype=“auto”).
The call reads the config, picks the model class, and loads the weights. The torch_dtype value sets the storage type, and device_map places each layer on a device. With auto, it fills the GPU first and then uses CPU or disk. It then sets the model to eval mode.
5. Compare BPE, WordPiece and Unigram tokenization. Why is `tokenizers` written in Rust, and what tokenizer bugs bite people in practice?
BPE merges the most frequent pairs, WordPiece merges by likelihood gain, and Unigram prunes a large vocabulary. The tokenizers library uses Rust for speed and safe parallelism. Common bugs are a tokenizer that does not match the model and wrong special token handling. A mismatch can add many extra tokens and slow training.
6. What problem do chat templates solve, and what goes wrong when they're ignored?
A chat template turns a message list into the exact text that a model saw in training. Each model family uses different role markers and turn endings. If you ignore the template, the model sees an odd prompt. Output quality drops and the model can fail to stop at the right place.
7. Fine-tune an 8B model on a single 24 GB GPU. Walk me through the memory maths and the exact stack you'd use.
Use 4-bit quantization with LoRA and keep the base weights frozen. In 4-bit, 8B weights take about 4 GB. LoRA states and activations fit in the rest, with a small batch and short sequences. Use bitsandbytes, peft, and trl SFTTrainer with gradient checkpointing.
model = AutoModelForCausalLM.from_pretrained(
name, load_in_4bit=True, device_map="auto")
model = get_peft_model(model, LoraConfig(r=16))
trainer = SFTTrainer(model=model, train_dataset=ds,
args=args)
8. You're building a web-scale pretraining corpus (FineWeb-style). Walk me through the pipeline and how you decide whether each filter earns its place.
The pipeline extracts text, applies language and quality filters, then removes duplicates. Each filter must show a gain on a small held-out benchmark. Measure the score before and after the filter on the same sample. Keep a filter only when the gain is larger than its cost in data and compute.
9. Design the Hugging Face Hub: millions of git repos where individual files are tens to hundreds of GB.
Use one git repository per model and store large weights outside git. Git holds small files and pointers. A content store holds each large file by its hash. This design keeps clones small and avoids duplicate uploads.
10. Design the serverless inference layer: any of thousands of Hub models can receive a request at any moment.
Load each model on first request and keep a warm pool for popular models. A router sends a request to a node that already holds the model. A cold start needs to pull tens of GB, so pre-warm the top models. The tradeoff is GPU cost for idle warm replicas.
11. A community contributor opens a PR adding a new model architecture to `transformers`. You're the reviewing maintainer: what do you check, and how do you handle the interaction?
Check the math against the reference implementation and confirm the config and tokenizer match. Ask for a slow test and a parity test with small weights. Request a conversion script and a clear model card. Review the code in small steps and reply with specific line comments.