Aprender

Cómo funciona de verdad la IA

Una guía en lenguaje sencillo sobre las palabras que ves en cada página de modelos — tokens, ventanas de contexto, caché, agentes, MCP, mezcla de expertos — con una demo práctica en cada capítulo y ejemplos reales de los 274 modelos que seguimos.

20 capítulos · unos 19 minutos · audio narrado

Las demos interactivas y las notas técnicas están en inglés.

01 · ¿Qué es la IA?

¿Qué es la IA?

La inteligencia artificial es software que aprende patrones a partir de ejemplos en lugar de seguir reglas escritas a mano. Un filtro de spam que ha visto millones de correos aprende cómo es el spam; nadie escribe cada regla.

La IA de las herramientas de programación es un modelo de lenguaje grande, o LLM. Se entrenó leyendo una enorme cantidad de texto y código — libros, webs, documentación, repositorios de código abierto — y ajustando miles de millones de números internos, llamados parámetros, hasta volverse muy bueno en una sola tarea: adivinar qué texto viene a continuación.

Parece poca cosa, pero para adivinar bien la siguiente línea de un programa, un modelo tiene que aprender gramática, hechos, las reglas de los lenguajes de programación y una idea práctica de cómo se resuelven los problemas. Todo lo que hace — responder preguntas, escribir código, corregir errores — se basa en esa única habilidad.

ProfundizarTransformers, layers and parameters · notas técnicas en inglés

Today's language models are transformers. Text becomes a sequence of token IDs; each ID is looked up in an embedding table to get a vector of a few thousand numbers (the model's width, d_model). That sequence of vectors then flows through a stack of identical blocks — 30 to 120 of them — and each block does two things:

  • Self-attention: every position looks back at earlier positions and pulls in the information it needs (which noun does “it” refer to, which variable was declared above).
  • A feed-forward network (MLP): a wide two-layer network applied to each position separately, where much of the model's stored knowledge lives.

Residual connections add each block's output back onto its input, and normalisation keeps the numbers in range. At the end, an unembedding matrix turns the final vector into one score (a logit) per vocabulary entry. Parameters are just the entries of all these matrices. For a dense model, a good estimate is:

params ≈ 12 × layers × d_model²   (+ vocab × d_model for embeddings)
# e.g. 32 layers, d_model 4096  →  12 × 32 × 4096² ≈ 6.4B  (+0.5B embeddings) ≈ "7B"

Nothing in that list is a rule about language. All of the behaviour comes from the values the parameters take during training.

02 · Cómo responde un modelo

Cómo responde un modelo

Construir un modelo tiene dos etapas. El entrenamiento es la parte cara: miles de chips trabajan durante semanas mientras el modelo lee sus datos y se ajustan sus parámetros. Después, el modelo queda congelado. La inferencia es lo que ocurre cuando lo usas: entra tu texto y el modelo produce una respuesta pieza a pieza.

En cada paso, el modelo mira todo lo escrito hasta ahora y asigna una probabilidad a cada posible siguiente pieza. Se elige una, se añade al texto y todo se repite hasta terminar la respuesta. Por eso las respuestas aparecen en pantalla palabra a palabra.

Un ajuste llamado temperatura controla lo atrevida que es esa elección. Con temperatura baja casi siempre gana la opción más probable, lo que conviene para el código. Con temperatura alta pasan palabras menos probables, lo que conviene para generar ideas.

Try itNext-token sampler

The best language for a quick script is

    Illustrative odds. At temperature 0 the top choice always wins; turn it up and the long tail starts getting picked.
    ProfundizarLogits, softmax, temperature and sampling · notas técnicas en inglés

    The model outputs a logit zᵢ for every token in its vocabulary. Softmax turns logits into probabilities, and temperature T divides them first:

    p(i) = exp(zᵢ / T) / Σⱼ exp(zⱼ / T)
    T → 0   : all probability on the top token (greedy decoding)
    T = 1   : the model's own distribution
    T > 1   : flatter — rare tokens get picked more often

    Samplers then trim the tail before picking: top-k keeps the k most likely tokens, top-p (nucleus) keeps the smallest set whose probabilities sum to p, and min-p drops tokens below a fraction of the top token's probability. Repetition and frequency penalties lower the logits of tokens already used. A fixed seed makes sampling repeatable on the same hardware and software.

    The generation loop

    tokens = tokenize(prompt)
    kv = prefill(tokens)                 # one parallel pass over the whole prompt
    while True:
        logits = forward(last_token, kv)  # one step, reusing the cached keys/values
        next = sample(logits, T, top_p)
        if next == END: break
        tokens.append(next); stream(next)

    Prefill is a big parallel matrix multiply and is limited by compute; each decode step is tiny and is limited by how fast weights can be read from memory. That split explains most of what you'll see about speed later in this guide.

    03 · Tokens

    ¿Qué son los tokens?

    Los modelos no leen letras ni palabras enteras. Leen tokens: trozos de texto que suelen ser una palabra, parte de una palabra o un símbolo. Las palabras comunes son un solo token; una palabra rara puede dividirse en dos o tres. En inglés, un token equivale a unos cuatro caracteres; en español suele hacer falta algo más de tokens para el mismo texto. El código usa más tokens por línea por sus símbolos y sangrías.

    Los tokens importan porque son la unidad con la que se mide y se cobra a los modelos. Los precios se dan por millón de tokens, con un precio para lo que envías (entrada) y otro para lo que el modelo escribe (salida). La salida suele ser varias veces más cara.

    Try itToken counter

    An approximation — every model family has its own tokenizer, so exact counts differ a little.
    ProfundizarByte-pair encoding and vocabularies · notas técnicas en inglés

    Most tokenizers use byte-pair encoding (BPE) or a close relative. Training starts from raw bytes and repeatedly merges the most frequent adjacent pair into a new token, until the vocabulary reaches its target size. Frequent strings (“ the”, “function”, four spaces of indentation) end up as single tokens; rare strings fall back to smaller pieces, and ultimately to individual bytes, so any text can be encoded.

    • Vocabulary sizes range from about 32,000 (older Llama, Mistral) to 150,000–260,000 (Qwen, Gemma, GPT-4o-era tokenizers). Bigger vocabularies mean fewer tokens per text but a bigger embedding table.
    • Languages are not treated equally. English averages about 4 characters per token; many other languages and scripts need noticeably more tokens for the same meaning, so they cost more and fill the context faster. Newer multilingual tokenizers have narrowed the gap.
    • Special tokens mark structure the user never types: start and end of a message, role markers such as <|im_start|>assistant, tool-call delimiters, image placeholders.
    • Numbers are tokenized oddly (“1234” might be “12” + “34”), which is one reason models used to struggle with arithmetic; many tokenizers now split digits individually.

    04 · Ventana de contexto

    La ventana de contexto

    La ventana de contexto es cuánto texto puede mirar un modelo de una vez: tus instrucciones, la conversación hasta ahora, los archivos que ha abierto un agente y la respuesta que está escribiendo. Es la memoria de trabajo del modelo. Lo que queda fuera, sencillamente no existe para él.

    El contexto se mide en tokens. Un modelo con una ventana de un millón de tokens puede abarcar unas 750.000 palabras a la vez: unas diez novelas o un proyecto de código mediano. Un modelo no recuerda tus chats anteriores por sí mismo; las herramientas le dan memoria volviendo a poner texto antiguo en la ventana. Cuando la ventana se llena, lo más antiguo se elimina o se resume.

    Try itFill the window

    • System prompt
    • Files
    • Chat
    • Logs
    • Repo
    When something new does not fit, the oldest items fall out of the window (the system prompt always stays).
    ProfundizarAttention cost, positions and the KV cache · notas técnicas en inglés

    In attention, every token computes a query, a key and a value. Each query is compared with every earlier key, and the resulting weights mix the values:

    Attention(Q, K, V) = softmax(Q·Kᵀ / √d) · V
    cost of prefill  ∝ n²   (every token vs. every earlier token)
    memory per token = 2 × layers × kv_heads × head_dim × bytes   ← the KV cache

    During generation the keys and values of past tokens are kept in the KV cache, so each new token only computes its own. That cache grows linearly with context and is often what limits long contexts — far more than the weights. Designs that shrink it: grouped-query attention (many query heads share a few KV heads), multi-head latent attention (DeepSeek; stores a compressed latent instead of full keys and values), sliding-window layers that only look back a few thousand tokens, and hybrids that mix in linear-attention or state-space layers with constant-size memory.

    Positions are encoded with RoPE (rotary embeddings), which rotate queries and keys by an angle that depends on position. Context windows are extended after training by stretching those angles (position interpolation, NTK scaling, YaRN) and fine-tuning briefly on long documents. Advertised and effective context differ: models retrieve facts from the start and end of a long prompt more reliably than from the middle, so put the most important material at the edges.

    05 · Prompts de sistema

    Prompts y prompts de sistema

    Todo lo que escribes es un prompt. Pero antes de que llegue tu mensaje, la aplicación ya ha enviado al modelo sus propias instrucciones ocultas: el prompt de sistema. Define quién es el modelo, qué herramientas puede usar, en qué estilo escribir y qué no debe hacer nunca. Los agentes de programación envían prompts de sistema largos, que explican cómo editar archivos, cuándo ejecutar pruebas y cuándo pedir permiso.

    Por eso el mismo modelo puede parecer totalmente distinto en dos herramientas: mismo cerebro, distintas instrucciones. Los buenos prompts son concretos: di qué quieres, da el contexto que el modelo no puede adivinar, muestra un ejemplo del resultado y explica qué significa «terminado».

    Try itSame question, different system prompt
    System

    You

    How do I reverse a list in Python?

    Model

    ProfundizarChat templates and structured output · notas técnicas en inglés

    A conversation is serialised into one token sequence by the model's chat template. The system prompt is simply the first message, wrapped in role markers:

    <|im_start|>system
    You are a careful coding assistant. Tools: read_file, run_tests …<|im_end|>
    <|im_start|>user
    How do I reverse a list in Python?<|im_end|>
    <|im_start|>assistant
    

    Models are trained to give the system role more authority than user or tool messages (an instruction hierarchy), but it's still just text in the same window. That's the root of prompt injection: instructions hidden in a web page, file or tool result can try to override the real ones. Agents defend with permissions, sandboxes and by treating tool output as data.

    Structured output goes further than asking nicely for JSON. With constrained decoding, the runtime compiles a JSON Schema or grammar into a state machine and masks the logits of any token that would break it, so the output is guaranteed to parse. llama.cpp calls these GBNF grammars; hosted APIs expose them as “structured outputs” or “JSON mode”.

    06 · Aciertos de caché

    ¿Qué es un acierto de caché?

    Un agente de programación envía al modelo el mismo gran bloque de texto una y otra vez: las instrucciones del sistema, los archivos del proyecto y la conversación. Solo cambian las últimas líneas en cada turno. Procesarlo todo desde cero cada vez sería lento y caro.

    La caché de prompts lo resuelve. El proveedor guarda el trabajo hecho sobre el comienzo de tu petición. Si la siguiente petición empieza exactamente con el mismo texto, reutiliza ese trabajo. Eso es un acierto de caché, y esos tokens se cobran con un gran descuento. Si cambia un solo carácter cerca del principio, todo lo que sigue es un fallo de caché y se cobra a precio completo.

    Las cachés duran poco — a menudo minutos —, así que ayudan sobre todo en sesiones intensas. El resultado es el mismo trabajo, mucho más barato y más rápido; por eso las herramientas se esfuerzan en mantener idéntico el comienzo de cada petición.

    Try itSession cost · Claude Sonnet 5.5 on Anthropic
    Without cache$5.36
    With cache hits$0.91

    83% cheaper with caching

    Each turn repeats the prefix, adds 2,000 new tokens and gets 1,000 back. Fresh input $2.00, cache hit $0.10 per million tokens (95% off).
    ProfundizarHow prefix caching works · notas técnicas en inglés

    What's cached is the KV cache of a prompt prefix — the keys and values computed during prefill. Serving engines split the cache into fixed blocks (vLLM's PagedAttention uses 16-token pages), hash each block together with everything before it, and reuse any block whose hash matches a new request. A change at position k changes the hash of every block after k, which is why one edited character near the start invalidates the rest.

    cost = cached_tokens × cache_read_price
         + new_tokens    × input_price
         + written_tokens × cache_write_price   (some providers)
         + output_tokens × output_price

    Some APIs cache automatically; others ask you to mark a breakpoint after the stable part (system prompt, tool definitions, documents). Practical rules: keep the stable material first and byte-identical (no timestamps in the system prompt), append rather than edit conversation history, and keep tool definitions in a fixed order. Entries are evicted after minutes of inactivity, or held longer for a fee. Running locally, llama.cpp and Ollama keep the last prompt's KV cache in memory, which is why a follow-up question starts answering almost instantly.

    07 · Tokens de razonamiento

    Tokens de razonamiento

    Algunos modelos pueden pensar antes de responder. En lugar de contestar enseguida, primero escriben una cadena de razonamiento privada: descomponen el problema, prueban un enfoque, lo comprueban y corrigen errores. Solo entonces escriben la respuesta final.

    Así son mucho mejores en problemas difíciles, como errores complicados, matemáticas o planificar un cambio grande. El inconveniente es que el pensamiento también está hecho de tokens. Los tokens de razonamiento se cobran como salida, aunque nunca los veas. Muchas herramientas te dejan elegir el nivel de esfuerzo, de bajo a alto.

    Try itReasoning effort · priced on Claude Opus 5.5

    Question: “Why does this test fail only on Mondays?” Token counts are typical, not exact.
    ProfundizarTest-time compute and reinforcement learning · notas técnicas en inglés

    Reasoning models are trained with reinforcement learning on verifiable tasks: maths with checkable answers, code with unit tests, puzzles with known solutions. The model generates long chains of thought; chains that end in a correct answer are rewarded. Over training, behaviours that help — breaking problems down, checking work, backtracking — become more frequent, and the chains get longer.

    This adds a second scaling axis: besides a bigger model, you can spend more test-time compute. Accuracy on hard problems rises roughly with the logarithm of the thinking budget, up to a point. Effort settings (low/medium/high) or explicit budget tokens cap that spend.

    • Thinking tokens are output tokens: billed as output and generated at decode speed, so they add latency as well as cost.
    • Many APIs return a summary or an encrypted copy of the reasoning instead of the raw chain; agents pass it back on the next turn so the model keeps its train of thought between tool calls (interleaved thinking).
    • More thinking isn't always better: simple lookups get slower and occasionally worse when a model over-thinks.

    08 · Herramientas y agentes

    Herramientas y agentes

    Por sí solo, un modelo solo puede escribir texto. Las llamadas a herramientas lo cambian. La aplicación le dice qué herramientas existen — leer un archivo, ejecutar un comando, buscar en la web — y cuando el modelo necesita una, escribe una petición estructurada en lugar de una respuesta normal. La aplicación ejecuta la herramienta de verdad y le devuelve el resultado. El modelo lo lee y decide qué hacer después.

    Pon eso en un bucle y tienes un agente: leer la prueba que falla, abrir el archivo, hacer un cambio, volver a ejecutar las pruebas, repetir hasta que pasen. Todos los agentes de programación de este sitio son, en el fondo, ese bucle.

    Try itStep through an agent loop
    ProfundizarTool definitions and the agent loop · notas técnicas en inglés

    A tool is described to the model as a name, a description and a JSON Schema for its arguments. The model replies with a structured call instead of text; the client executes it and sends the result back as a tool message.

    {"name": "run_tests",
     "description": "Run the project's test suite and return failures",
     "input_schema": {"type": "object",
       "properties": {"path": {"type": "string"}}, "required": []}}
    
    messages = [system, user]
    while True:
        reply = model(messages, tools)
        if not reply.tool_calls: return reply.text
        for call in reply.tool_calls:            # may run several in parallel
            result = execute(call)               # sandbox + permission checks here
            messages += [reply, tool_result(call.id, result)]

    What separates good agents from bad ones is mostly around this loop: precise tool descriptions, small and composable tools, truncating huge outputs, asking permission for risky actions, and context management — summarising or dropping old tool results so long sessions don't overflow the window. tool_choice can force a specific tool or forbid tools; constrained decoding keeps the arguments valid JSON.

    09 · MCP

    MCP, el Model Context Protocol

    Cada herramienta que usa un modelo tiene que conectarla alguien. Antes de MCP, cada aplicación conectaba cada servicio a su manera. El Model Context Protocol es un estándar común para esa conexión: piensa en él como el USB-C de las herramientas de IA.

    Un servidor MCP envuelve un servicio — GitHub, una base de datos, un navegador, tus archivos de diseño — y describe las herramientas que ofrece. Cualquier aplicación que hable MCP puede conectarlo y el modelo puede usar esas herramientas de inmediato. Escribes el servidor una vez y funciona en todas partes; por eso aparecieron tantos tan rápido.

    Try itPlug in a server
    MCP clientYour coding agent0 tools available
    Click servers to plug them in. Each one adds its tools to what the model can do — no changes to the model or the app.
    ProfundizarInside the protocol · notas técnicas en inglés

    MCP is JSON-RPC 2.0 between a client (inside the agent or IDE) and a server. Local servers run as a subprocess and talk over stdio; remote ones use Streamable HTTP, with OAuth 2.1 for login. The session starts with an initialize handshake in which both sides declare their capabilities.

    → {"jsonrpc":"2.0","id":1,"method":"tools/list"}
    ← {"jsonrpc":"2.0","id":1,"result":{"tools":[{"name":"create_issue",
         "description":"Open a GitHub issue","inputSchema":{…}}]}}
    → {"jsonrpc":"2.0","id":2,"method":"tools/call",
       "params":{"name":"create_issue","arguments":{"title":"Fix login"}}}

    Servers offer three primitives: tools (actions the model can call), resources (data the app can read into context, addressed by URI) and prompts (reusable templates the user can invoke). Clients can offer sampling (the server asks the host's model to generate text) and elicitation (the server asks the user a question). Every tool's schema is sent to the model, so dozens of servers can eat thousands of tokens of context — one reason agents now load tool definitions lazily.

    10 · UTCP

    UTCP, el Universal Tool Calling Protocol

    MCP pone un servidor entre el modelo y el servicio. El Universal Tool Calling Protocol parte de otra pregunta: si un servicio ya tiene una API, ¿por qué envolverlo en otro servidor? UTCP es un estándar abierto que permite al agente llamar a la herramienta directamente.

    Cada herramienta publica un manual: un archivo JSON que indica qué hace cada herramienta, qué datos recibe y cómo llamarla. El agente lee el manual una vez y después habla con el servicio por su propio protocolo, como HTTP o la línea de comandos, con el inicio de sesión del propio servicio.

    La pega es que el trabajo cambia de sitio, no desaparece. El cliente del agente tiene que hablar cada protocolo y gestionar inicios de sesión, reintentos y errores, y cada herramienta es responsable de su propia seguridad. MCP además tiene muchos más servidores y apoyo de empresas.

    No hace falta elegir para siempre: UTCP tiene un complemento para llamar a servidores MCP existentes.

    Try itFollow one tool call
    Your agent MCP server Weather API
    The agent sends
    Someone maintains
    Login handled by
    {
      "manual_version": "1.0.0",
      "utcp_version": "1.0.1",
      "tools": [{
        "name": "get_weather",
        "description": "Get current weather for a location",
        "inputs": {
          "type": "object",
          "properties": { "location": { "type": "string" } },
          "required": ["location"]
        },
        "tool_call_template": {
          "call_template_type": "http",
          "url": "https://api.example.com/weather",
          "http_method": "GET"
        }
      }]
    }
    Switch protocols to compare the same weather lookup. The API is a made-up example.
    ProfundizarManuals and call templates · notas técnicas en inglés

    A UTCP manual lists tools, each with JSON Schema inputs and outputs and a tool_call_template saying how to reach it. Templates exist for HTTP, server-sent events, streamable HTTP, the command line, text files and MCP itself. The client substitutes the arguments into the template and calls the service directly, with the service's own authentication (API key, OAuth or basic auth, declared in the template and filled from local variables).

    agent ──reads manual once──▶  /utcp  (JSON)
    agent ──GET /weather?location=Oslo──▶  api.example.com   # no proxy in between

    The trade-off versus MCP: no extra server process and no extra hop, and existing APIs work as they are; but the client must implement every transport, and features MCP standardises — resources, prompts, sampling, server-initiated notifications — are out of scope.

    11 · Embeddings y RAG

    Embeddings y RAG

    Los ordenadores no pueden comparar significados directamente, así que los modelos convierten el texto en listas de números llamadas embeddings. Cada una es un punto en un espacio de cientos de dimensiones, y los textos con significados parecidos quedan cerca: «arregla el fallo de inicio de sesión» queda junto a «error de autenticación», aunque no compartan palabras.

    Eso permite buscar por significado: conviertes cada documento una vez, conviertes cada pregunta y tomas los documentos más cercanos. La generación aumentada por recuperación, o RAG, mete esos documentos en la ventana de contexto antes de que el modelo responda. Así un modelo puede contestar sobre tu código sin haberse entrenado con él.

    Try itSearch by meaning
      A 2-D sketch of a space that really has hundreds of dimensions. The three closest documents are what RAG would hand to the model.
      ProfundizarVectors, similarity and retrieval pipelines · notas técnicas en inglés

      An embedding model maps text to a vector, typically 384 to 4,096 dimensions. Similarity is usually cosine similarity:

      cos(a, b) = (a · b) / (‖a‖ ‖b‖)      # 1 = same direction, 0 = unrelated

      Search over millions of vectors uses approximate nearest-neighbour indexes such as HNSW graphs or IVF clusters, in a vector database or a library like FAISS. A production RAG pipeline usually adds:

      • Chunking: split documents into passages of a few hundred tokens, ideally along headings or function boundaries, with some overlap.
      • Hybrid search: combine vectors with keyword search (BM25), which catches exact names, error codes and identifiers that embeddings blur.
      • Reranking: a cross-encoder scores the top 50–100 candidates against the question and keeps the best handful.
      • Grounded prompting: put the passages in the context with their sources and ask the model to cite them.

      Coding agents often skip vectors entirely and search with grep-style tools in a loop — exact, always up to date, and good enough when the model can iterate.

      12 · Alucinaciones

      Por qué los modelos alucinan

      El trabajo de un modelo es producir texto probable, no texto verdadero. Normalmente coinciden; cuando no, puede afirmar algo falso con total seguridad. Eso es una alucinación.

      En el código aparecen como una función que no existe, una opción de configuración que nunca se añadió o un nombre de paquete que suena perfecto. Son más frecuentes con bibliotecas poco conocidas, cambios recientes y detalles exactos. Las defensas: dar al modelo la fuente real (documentación, archivos, búsqueda), dejarle ejecutar el código y las pruebas, y comprobar todo lo importante.

      Try itSpot the made-up answer

      Each question has two real answers and one a model might plausibly invent.
      ProfundizarWhy it happens and how it is measured · notas técnicas en inglés

      Pre-training rewards predicting plausible text, not saying “I don't know”; benchmarks that grade only right or wrong reward guessing over abstaining. So a model that hasn't stored a fact still produces the most fact-shaped continuation. Rare facts — seen a handful of times in training — are the most at risk, which is why niche libraries and recent APIs suffer most.

      • Calibration measures whether stated confidence matches accuracy. Some evaluations now score abstentions separately and penalise confident errors.
      • Grounding (RAG, search, reading the actual source file) moves the answer from memory to the context, where models are much more reliable.
      • Verification loops — run the code, run the tests, type-check, call the real API — catch invented functions immediately.
      • Package hallucinations are a security problem: attackers register package names that models tend to invent (“slopsquatting”). Check that a dependency exists and is the one you meant before installing it.

      13 · Cómo se entrenan

      Cómo se entrenan los modelos

      Un modelo se construye por etapas. Primero viene el preentrenamiento: lee billones de tokens y aprende a predecir el siguiente. De ahí sale su conocimiento, y es con diferencia el paso más caro, pero el resultado todavía no es un asistente útil.

      Después, el ajuste fino con ejemplos de buenas conversaciones le enseña a seguir instrucciones. Por último, el aprendizaje por refuerzo: intenta tareas, sus respuestas se puntúan — por personas, por otros modelos o con comprobaciones automáticas como si el código pasa sus pruebas — y se premian las buenas. Ese último paso explica en gran parte lo rápido que han mejorado los modelos de programación.

      Try itSame prompt, three stages
      Prompt

      Write a function that checks whether a word is a palindrome.

      Model after pre-training

      ProfundizarLoss, compute and post-training · notas técnicas en inglés

      Pre-training minimises cross-entropy loss: the negative log-probability the model gave to each actual next token, averaged over trillions of tokens. Gradients from that loss nudge every parameter, batch after batch.

      loss = − (1/N) Σ log p(tokenₜ | tokens<ₜ)
      training compute ≈ 6 × parameters × training tokens   (FLOPs)
      # 70B params × 15T tokens ≈ 6.3 × 10²⁴ FLOPs

      Scaling laws describe how loss falls predictably with more parameters, data and compute; modern models are trained on far more tokens per parameter than the old “compute-optimal” ratio of about 20, because a smaller model that's been trained longer is cheaper to serve.

      Post-training turns the predictor into an assistant: supervised fine-tuning on curated conversations; preference optimisation (RLHF with a reward model, or DPO directly on pairs of better/worse answers); and RL with verifiable rewards for maths, code and agent tasks, run in sandboxes with real tools. Distillation trains a smaller model on a larger one's outputs, which is how many fast “mini” and “flash” models are made.

      14 · Mezcla de expertos

      Mezcla de expertos

      Un modelo normal, o denso, usa todos sus parámetros para cada token. Un modelo de mezcla de expertos (MoE) se divide en muchas subredes más pequeñas llamadas expertos. Para cada token, un pequeño enrutador elige solo unos pocos expertos y el resto descansa.

      Resultado: el modelo guarda el conocimiento de una red enorme, pero cada token cuesta como uno pequeño. Por eso se indican por separado los parámetros totales y los activos. El tamaño total decide cuánta memoria hace falta para alojarlo; el tamaño activo decide lo rápido y barato que es cada token.

      Try itRoute tokens through experts

      token router expert 1expert 2expert 3expert 4expert 5expert 6expert 7expert 8
      Different tokens wake different experts. Over a sentence, most experts get used — but only 2 of 8 at a time.
      ProfundizarRouters, top-k gating and load balancing · notas técnicas en inglés

      In an MoE layer the feed-forward network is replaced by E experts and a router. For each token the router computes a score per expert, keeps the top k and mixes their outputs by those scores:

      g = softmax(W_router · x)          # one weight per expert
      y = Σ_{i ∈ topk(g)} gᵢ · Expertᵢ(x)
      active params ≈ shared (attention, embeddings, shared experts) + k/E × expert params

      Modern MoEs use many small experts (128–384) with 4–10 active, often plus one always-on shared expert. Training adds a load-balancing term (or a bias adjustment) so tokens spread evenly; otherwise a few experts take all the work. Serving at scale uses expert parallelism — experts spread over many GPUs, tokens routed between them. At home the useful fact is the asymmetry: memory scales with total parameters, speed with active ones, and the rarely-used experts can sit in system RAM while attention runs on the GPU.

      15 · Cuantización

      Cuantización (fp8, fp4)

      Cada parámetro es un número, y los números se pueden guardar con más o menos precisión. La cuantización los guarda con menos bits — por ejemplo 8 bits (fp8) o 4 bits (fp4) en lugar de 16. El modelo ocupa menos y es más rápido y normalmente más barato de servir, a cambio de una pequeña pérdida de calidad, a veces apreciable.

      Por eso el mismo modelo abierto puede costar distinto según el proveedor: quizá ejecutan precisiones distintas en hardware distinto.

      Try itShrink a model

      The orange line is a smooth signal stored with the chosen precision: fewer bits, fewer levels, more rounding.
      ProfundizarScales, blocks and quantization formats · notas técnicas en inglés

      Quantization maps each weight to a small integer and stores a scale (and sometimes an offset) per block of weights:

      q = round(w / scale)           # e.g. a 4-bit integer in [-8, 7]
      w ≈ q × scale                  # what the GPU reconstructs on the fly
      bits per weight = bits + (scale bits / block size)
      # Q4_K: blocks of 32 inside super-blocks of 256, 6-bit scales → ~4.5 bpw;
      # Q4_K_M keeps some tensors at Q6_K → ~4.85 bpw on average
      • Post-training quantization methods (GPTQ, AWQ, llama.cpp's importance matrix) use a little calibration text to decide where precision matters most and round to minimise output error, not weight error.
      • Hardware formats: FP8 (E4M3) is native on recent NVIDIA, AMD and Intel accelerators; MXFP4 and NVFP4 are 4-bit floats with shared block scales supported by the newest GPUs, so 4-bit can run at full speed instead of being unpacked.
      • Quantization-aware training (QAT) simulates low precision during training, so the released 4-bit model loses almost nothing.
      • Quality loss is measured with perplexity or, better, the KL divergence between the quantized and full-precision output distributions, plus task benchmarks.

      16 · Pesos abiertos y cerrados

      Pesos abiertos y cerrados

      Los pesos de un modelo son sus parámetros aprendidos: el archivo que es el modelo. Los modelos cerrados los mantienen privados: solo puedes usarlos mediante la aplicación o la API del laboratorio. Los modelos de pesos abiertos los publican, así que cualquiera puede descargarlos, ejecutarlos, ajustarlos o revender el acceso.

      Los modelos cerrados suelen haber ido por delante en capacidad bruta. Los abiertos te dan elección: muchos proveedores compitiendo en precio y velocidad, datos que se quedan en tus máquinas y un modelo que sigue funcionando aunque su creador cambie de rumbo.

      Try itThe models we track
      Price is per million input tokens.
      ProfundizarLicences, formats and fine-tuning · notas técnicas en inglés

      “Open weights” isn't automatically “open source”. Licences range from permissive (Apache 2.0, MIT) to custom ones with usage policies, attribution rules or limits for very large companies. The Open Source Initiative's definition of open-source AI also asks for enough information about the training data to reproduce the model, which few releases provide.

      Weights are distributed as safetensors files (a simple, memory-mappable format that can't execute code, unlike old pickle checkpoints) with a config.json describing the architecture and a tokenizer. Community conversions add GGUF (llama.cpp) and MLX (Apple).

      Open weights can be fine-tuned. LoRA freezes the model and trains a low-rank update for selected matrices — W' = W + B·A, with A and B thin — so only a fraction of a percent of the parameters train; QLoRA does this on a 4-bit base model, which puts fine-tuning a 30B model within reach of a single 24 GB GPU.

      17 · IA en casa

      Ejecutar la IA en casa

      Los modelos de pesos abiertos pueden funcionar en tu propio ordenador. Un programa llamado runtime — Ollama, LM Studio o llama.cpp — carga los pesos del modelo en memoria, idealmente en la memoria de tu tarjeta gráfica (VRAM), y genera texto igual que lo haría un proveedor en la nube. Nada sale de tu máquina, no pagas por token y funciona sin conexión.

      Dos números deciden qué puedes ejecutar. La memoria decide qué modelos caben: aproximadamente parámetros × bits por peso ÷ 8, más espacio para el contexto. Un modelo de 8.000 millones de parámetros a 4 bits necesita unos 5 GB; uno de 70.000 millones, más de 40 GB. El ancho de banda de memoria decide la velocidad, porque cada token nuevo obliga a leer de nuevo todos los pesos activos; por eso los modelos de mezcla de expertos, con pocos parámetros activos, son tan populares en casa.

      Abre la calculadora: detecta tu hardware, te dice qué modelos funcionarán y a qué velocidad, qué ajustes o mejoras te ayudarían y los comandos exactos para instalarlos.

      Try itWill it run?

      Check your own computer →

      Simplified: weights plus a 16K-token context. The full calculator uses each model’s real size and attention shape.

      Comprueba qué puede ejecutar tu ordenador →

      ProfundizarThe memory and speed formulas · notas técnicas en inglés
      memory  ≈ params × bpw / 8 + KV cache + ~0.8 GB
      KV      = 2 × layers × kv_heads × head_dim × 2 bytes × context
      tok/s   ≈ 0.65 × bandwidth / (active_params × bpw / 8)
      
      RTX 4090 (1008 GB/s), 32B dense @ Q4_K_M (19.4 GB):  ≈ 34 tok/s
      Apple M4 Max (546 GB/s), 30B-A3B MoE @ Q4 (1.8 GB/token): ≈ 100+ tok/s
      Dual-channel DDR5 (~80 GB/s), 8B @ Q4 (4.9 GB): ≈ 10 tok/s

      Offloading splits the bytes read per token between fast VRAM and slow system RAM; the slow part dominates. Mixture-of-experts models offload best: keep attention, embeddings and shared experts on the GPU (they're read every token), and put routed experts in RAM (each is read only when chosen). The Run AI at home page applies these formulas to every open model with its real attention shape.

      18 · Multimodal

      Modelos multimodales

      Los primeros modelos de lenguaje solo manejaban texto. Los modelos multimodales también aceptan imágenes, PDF, audio e incluso vídeo. Para programar es sorprendentemente útil: pega una captura de un diseño roto o una maqueta y pide al modelo que la construya, o deja que un agente haga capturas de la aplicación para revisar su propio trabajo.

      Por dentro, una imagen también se convierte en tokens. Se corta en pequeños parches y cada parche se convierte más o menos en un token; así, una imagen grande puede ocupar tanto contexto como una página de texto.

      Try itHow many tokens is an image?

      Uses one common rule of thumb — about one token per 750 pixels. Each provider resizes and counts a little differently.
      ProfundizarVision encoders and image tokens · notas técnicas en inglés

      Most multimodal LLMs bolt a vision encoder (a Vision Transformer) onto the language model. The image is resized, cut into patches (often 14×14 or 16×16 pixels), each patch becomes a vector, and a small projector maps those vectors into the language model's embedding space, where they sit in the sequence like word tokens. Many models merge neighbouring patches 2×2 to save tokens:

      image tokens ≈ (width / 28) × (height / 28)    # 14-px patches, 2×2 merge
      1024 × 768  →  ~37 × 27 ≈ 1,000 tokens

      Providers cap the resolution or tile large images, so counts differ by API. Audio is handled the same way — a speech encoder turns audio frames into embeddings — and video as a sequence of sampled frames. “Natively multimodal” models are pre-trained on mixed text and images from the start rather than having vision added later. Generating images is usually a separate system (diffusion, or autoregressive image tokens).

      19 · Velocidad

      Velocidad: latencia y rendimiento

      Dos números deciden lo rápido que se siente un modelo. La latencia, o tiempo hasta el primer token, es cuánto esperas antes de que aparezca algo. El rendimiento, en tokens por segundo, es lo rápido que fluye el texto una vez empieza. Para una pregunta rápida importa más la latencia; para un agente que escribe un archivo grande, el rendimiento.

      La velocidad depende del tamaño del modelo, de lo ocupado que esté y del hardware y software de quien lo sirve. Los modelos de razonamiento además pasan un tiempo pensando antes de que empiece la respuesta visible.

      Try itFeel the difference
      
          
      0.0 s
      ProfundizarThe roofline: compute vs memory bandwidth · notas técnicas en inglés

      A chip is limited either by arithmetic (FLOPs per second) or by how fast it can move data (bytes per second). The ratio of work to data — arithmetic intensity — decides which:

      decode, batch 1 : ~2 FLOPs per weight byte read  → memory-bound
      prefill, 2k tok : ~4,000 FLOPs per weight byte    → compute-bound
      time to first token ≈ queueing + prefill(prompt) + network

      That's why serving providers batch many users together: reading the weights once and applying them to 64 requests makes decode far more efficient, at a small latency cost per user. Speculative decoding exploits the same slack for one user: a cheap draft (a small model, or extra prediction heads) proposes several tokens, the big model verifies them all in one parallel pass and keeps the prefix it agrees with — identical output, often 2–3× faster when drafts are accepted. Specialised chips (Cerebras, Groq, SambaNova) keep weights in on-chip SRAM with enormous bandwidth, which is how they reach thousands of tokens per second.

      20 · Benchmarks

      Cómo leer los benchmarks

      Un benchmark es una prueba estándar: las mismas tareas para todos los modelos, para poder comparar puntuaciones. Algunos miden conocimiento y razonamiento con preguntas difíciles tipo examen; los de programación dan al modelo errores reales de proyectos reales y comprueban si su arreglo hace pasar las pruebas.

      Léelos con cuidado. Un modelo puede haber visto las preguntas durante el entrenamiento, lo que infla su nota; los laboratorios eligen qué resultados mostrar; y una buena nota en un tipo de tarea dice poco de otra. El mejor benchmark es tu propio trabajo: prueba varios modelos en lo que haces de verdad.

      Try itTop tracked models

      Real GitHub issues fixed in Python repos.

      Scores from Epoch AI. Compare many more on the leaderboard.
      ProfundizarContamination, pass@k and arena ratings · notas técnicas en inglés
      • Contamination: if test questions leaked into training data, scores measure memory. Defences include held-out private test sets, fresh problems dated after a model's cutoff (LiveCodeBench-style) and checking whether a model can complete a question it shouldn't know.
      • pass@k for code is the probability that at least one of k samples passes the tests, estimated without bias from n ≥ k samples with c correct: pass@k = 1 − C(n−c, k) / C(n, k). Agentic benchmarks such as SWE-bench Verified give the model a real repository and issue, then run the project's hidden tests on its patch.
      • Arena ratings come from people comparing two anonymous answers; a Bradley–Terry model turns millions of votes into Elo-like scores. They measure preference — including style and length — not correctness.
      • Watch the error bars: on a 500-question test, ±2 points is often noise. And benchmarks saturate — once top models score above 90%, differences stop meaning much and a harder test replaces it.

      Ejemplos calculados a partir del catálogo público de modelos y proveedores. Narración con voz de Magnific.