Coders In Hoods
  • Courses
  • Roles
  • Blog
  • Setup

Coders In Hoods AI Academy

Every course is free. Sign in to start, and your progress, quiz scores and bookmarks follow you.

AI Academy

  • Courses
  • Paths
  • Setup guides
  • How we teach

Role roadmaps

  • AI Engineer
  • Forward Deployed Engineer
  • Machine Learning Engineer
  • All roles

Coders In Hoods

  • The agency
  • Coaching for teams
  • Blog
  • LinkedIn
  • X (Twitter)

Contact

codersinhoods@gmail.com

© Coders In Hoods · since 2019

Course overview

Serving Open-Weight Models

Free · sign in to start and track progress

1 · What the server does with your GPU

  • 1Inside an inference engine
  • 2GPU sizing arithmetic
  • 3Serving your adapter

2 · Smaller, faster, still correct

  • 4Quantisation with evidence
  • 5Latency, throughput and honest benchmarks
  • 6Speculative decoding in practice
  • 7Structured outputs and tool calls

    Exercise answers

    • Answer: Build a guided sampler, then use the server's
    • Answer: Tool calls on an open model

3 · Ship it and run it

  • 8What self-hosting makes you responsible for
  • 9Deployment and rollout
  • 10Observability and operations
CapstoneShip the triage endpointReference implementation

Module 2 · Smaller, faster, still correct · Lesson 7

Structured outputs and tool calls

The server can mask every token that would break your schema or grammar, which guarantees a parse but not a correct answer; tool calling on an open model is the same machinery plus a parser for the model's call format.

90 min 1 video 3 exercises 7-question quiz Answers
Setup for the exercises:Install Claude CodePython with uvInstall llama.cppThe Quillmoor triage kitServe a model with vLLMRun GPU code on Modal

By the end of this lesson you can

  • Explain token-level constrained decoding, from a regex compiled to a finite-state machine to a JSON schema run by a pushdown automaton, including the token-terminal mismatch and how vocabulary indexing resolves it
  • Request JSON schema, regex, choice and grammar constraints from vLLM, SGLang and llama.cpp, and choose a backend
  • Serve tool calling from an open model with a tool-call parser, and use auto, required and named tool choice
  • Measure the quality effect of constraints with your evals instead of assuming it, and keep the schema in the prompt as well
  • Compare hosted structured outputs with what you own when the mask runs on your server

On this page

  • Intuition: the mask on the logits
  • The mechanism
  • Regex to finite-state machine
  • JSON schema to pushdown automaton
  • The token-terminal mismatch
  • Worked example: the mask at "priority": "
  • Asking the server
  • Tool calling on an open model
  • Hosted versus self-owned
  • Connections
  • Summary
  • Sources & further reading
  • Quiz

In this lesson

  1. 01Intuition: the mask on the logits
  2. 02The mechanism
  3. 03Worked example: the mask at "priority": "
  4. 04Asking the server
  5. 05Tool calling on an open model
  6. 06Hosted versus self-owned
  7. 07Connections
  8. 08Summary

Sources & further reading

  • Efficient Guided Generation for Large Language ModelsPaper · Willard, Louf · 2023The seminal construction (Outlines): a regex becomes a finite-state machine, and indexing the vocabulary by state turns the per-token mask into a lookup. Sections 2 and 3.
  • XGrammar: Flexible and Efficient Structured Generation Engine for Large Language ModelsPaper · Dong, Ruan, Cai, Lai, Xu et al. · CMU · 2024The default backend in vLLM and SGLang. Context-independent tokens precomputed into an adaptive token-mask cache, a persistent execution stack for the pushdown automaton, and grammar work overlapped with GPU compute. Sections 3 and 4.
  • Grammar-Constrained Decoding for Structured NLP Tasks without FinetuningPaper · Geng, Josifoski, Peyrard, West · 2023Evidence (EMNLP 2023) that a grammar at decode time lets an untuned model do structured tasks it otherwise fails at, which is the case for constraints; read with the next paper for the case against relying on them blindly.
  • Grammar-Aligned DecodingPaper · Park, Wang, Berg-Kirkpatrick, Polikarpova, D'Antoni · 2024Why masking token by token distorts the distribution relative to conditioning on the constraint, and a corrected sampler (NeurIPS 2024). The quality caveat in this lesson comes from Section 3.
  • vLLM structured outputsDocs · vLLM`response_format` with `json_schema`, the `structured_outputs` options (`choice`, `regex`, `grammar`, `structural_tag`), the `--structured-outputs-config.backend` flag, and the advice to describe the schema in the prompt too.
  • vLLM tool callingDocs · vLLM`--enable-auto-tool-choice`, `--tool-call-parser` and the parser list by model family, `tool_choice` values, strict mode, and the sentence that a named call is guaranteed parsable but not high-quality.
  • llama.cpp HTTP serverDocs · ggml`-j/--json-schema`, `--grammar`, the per-request `json_schema` and `grammar` fields, `response_format` in both forms, and `--jinja` for tool-call templates.
Free · sign in to start

Sign in to keep reading.

Free, no card. We use your account to save progress, quiz scores, bookmarks and occasionally send updates from our team.

  • 8 more sections
  • 3 hands-on exercises
  • A 7-question quiz
  • Progress, quiz scores and bookmarks