How structured outputs work under the hood (via breakout at OpenAI DevDay)
Guess why the first structured output request is slow, but the 2nd+ is fast?
Engineering:
* Unconstrained token decoding isn't good. The model could pick any token.
* Limiting which tokens can be produced next is what works. They use "token masking" for this. Constrains the token which are picked at the end of sampling
* After generating probabilities with a forward pass, ignore (or mask) tokens you know aren't applicable.
* Mask tokens need updating at every step of the inference. Needs to be really fast. Mask determination happens on the CPU. Needs it to be as quick, as quick as time between tokens. <10ms
* They build up an index with the JSON schema you apply to speed up mask making
* Index Making: Grammar > Parser > Iterate over all tokens and parse states > Index. Index once, cache later. First query to structured outputs go slow, then the 2nd+ query is quick.
* Recursive schema makes this hard. But they believe they will be a big deal so they are moving towards it.
* CFG: Context Free Grammar approach. Regular expression + stack. Their attempt at indexing
Research
* Retraining and fine tuning gets you to 100% schema adherence
API Design
* Additional properties: What do you do with properties that were note defined in the schema? Decided to disallow them
* Design principle, be explicit instead of implicit. Requiring developers to set properties. It's harder to use, but communication is more clear
* Design principle: All properties are design by default. It makes optional params nullable
* Decided to generate fields in the same order they were defined in the schema, this helps with requiring chain of thought for structured outputs
We made a step-by-step tutorial on how to finetune Llama-3 with Google Colab & deploy it to @Ollama
Tutorial: https://t.co/YtxXzlFOSp
Colab notebook: https://t.co/FnmHK9sysS
Blog post & video coming soon. 🦥
❓What is an agent?
I get asked this question a lot, so I wrote a little blog on this topic and other things:
- What is an agent?
- What does it mean to be agentic?
- Why is “agentic” a helpful concept?
- Agentic is new
Check it out here: https://t.co/KCwYmzSd5Z
This is an interesting overview of what it is like to actually build production software with today's LLMs. It also shows how weird LLMs are to work with from a software perspective & how much we have to learn.
It is why I stress co-intelligence for now. https://t.co/DIQrGqIa5P
@mariaersh@ian_eck @jtmorehead_ @joulee I love notion but not having an offline mode like https://t.co/6H9YA41Sxy or Evernote makes it feel slow since it seems to be fetching all the pages on load.