Deep dive on LLM Inference at Scale — Harshul Jain, Audible & Tanmay Sah, Independent AI Researcher

Read the talk

LLM Inference at Scale: From KV Memory to Serving Engines

Selected presentation frame from Deep dive on LLM Inference at Scale — Harshul Jain, Audible & Tanmay Sah, Independent AI Researcher at 972 seconds
LLM Inference at Scale: From KV Memory to Serving Engines

Harshul Jain and Tanmay Sah explain why context, concurrency, and token generation strain GPUs, then connect each bottleneck to model and serving optimizations.

From a talk by Harshul Jain and Tanmay Sah

At a glance

Ideas worth remembering

  • A model fitting in GPU memory is only the starting point. KV state grows with context and concurrent sequences, while latency objectives can reduce usable concurrency below the memory ceiling.

  • Prefill and decode demand different optimizations: prefill performs substantial prompt computation, while decode repeatedly accesses weights and KV history for each new token. TTFT and inter-token latency must be assessed separately.

  • Weight quantization frees space for KV state; KV quantization reduces the state itself. Neither memory reduction alone proves higher throughput or preserved quality.

  • Paging reduces allocation waste, continuous batching reduces unused scheduling capacity, and prefix caching avoids repeated prompt computation. Each mechanism targets a different source of inefficiency.

  • The corrected latent-attention saving is 14-fold for the workshop example. The earlier 50–56-fold calculation omitted a layer multiplier, showing why comparisons must include the full architecture.

  • The presenters report similar vLLM and SGLang performance on standard requests and a three-to-four-times SGLang advantage in their agentic branching setup. Their recommendation is workload-specific, and they explicitly allow for different results elsewhere.

  • Choose the model and service requirements before selecting optimizations. Evaluate useful token throughput under those constraints, then pursue deeper cache or distributed-inference techniques only when they address a bottleneck the workload actually has.

Why inference becomes an operating-cost problem

Selected presentation frame from Deep dive on LLM Inference at Scale — Harshul Jain, Audible & Tanmay Sah, Independent AI Researcher at 395 seconds
Why inference becomes an operating-cost problem

Harshul Jain and Tanmay Sah open with a first-principles workshop for beginners and intermediate practitioners. The sequence follows a practical question: what makes inference expensive, what causes its bottlenecks, and which optimizations address those causes? They divide the interventions into changes to the model and changes to the system that serves it, before comparing inference engines.

The economic distinction is between training expenditure and recurring inference expenditure. Serving continues to consume resources as users arrive, sessions begin, and tokens pass through the system. Jain uses market estimates and a historical training-cost example to motivate the problem, but the useful engineering conclusion does not depend on those estimates: limited hardware and expensive computation make usage growth an operating-cost concern. Reducing token usage and making inference more efficient are the two responses he emphasizes.

The accompanying repository gathers slides, a benchmark report, and prepared Jupyter notebooks. Its purpose is to make scattered inference material easier to study and experiment with. The workshop's larger goal is similarly durable: understanding the underlying constraints should help practitioners evaluate subsequent optimizations instead of treating each new solution as an unrelated trick.

0:220:32
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

0:13 · section reference included

Three symptoms in a simple inference implementation

Selected presentation frame from Deep dive on LLM Inference at Scale — Harshul Jain, Audible & Tanmay Sah, Independent AI Researcher at 539 seconds
Three symptoms in a simple inference implementation

The first demonstration loads a roughly 15 GB model and examines GPU memory consumption. Jain initially walks through previously obtained results because of conference connectivity concerns. Loading the weights establishes a baseline, but inference consumes additional memory as the input grows. Contexts of 4,000, 16,000, or 32,000 tokens can therefore create an out-of-memory problem even when the model itself fits comfortably.

The second symptom is rising time to first token, abbreviated TTFT. A longer prompt makes the user wait longer before generation begins. Jain explicitly corrects his terminology here: the changing variable is context size, meaning the number of input tokens, rather than the size of an individual token. Memory growth and startup latency respond to the same increase in prompt length, although their mechanisms will differ.

The third symptom is poor throughput, measured as tokens or users served per second. In the simple implementation, five incoming requests are answered sequentially. Later requests wait for earlier work, so completion time increases with multiple users. These three observations—memory, TTFT, and throughput—establish the questions the rest of the workshop answers.

7:467:49
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

7:31 · section reference included

Attention explains why memory grows with context

Selected presentation frame from Deep dive on LLM Inference at Scale — Harshul Jain, Audible & Tanmay Sah, Independent AI Researcher at 876 seconds
Attention explains why memory grows with context

The inference pipeline begins by converting text into tokens, mapping those tokens to embeddings, and passing them through transformer layers. The workshop temporarily treats one word as one token for simplicity; this is a teaching assumption. A generated token becomes part of the input for the next generation step, creating an autoregressive loop. The Mistral 7B example uses 32 transformer layers, while other models can have different layer counts.

Inside a transformer layer, Jain identifies normalization, attention, and feed-forward computation, then focuses on attention. Each token is projected into query, key, and value vectors. Attention determines how a token relates to preceding tokens, which requires access to their keys and values. Ten tokens need ten sets of these representations; a thousand tokens need a thousand. Keeping the keys and values therefore creates storage that grows with sequence length.

The KV calculation multiplies the two stored vectors, their 128-dimensional size, the 32 layers, the number of KV heads, and the storage precision. For the workshop's configuration, Jain gives approximately 131 KB per token. That becomes roughly half a GB at 4K context and 2.1 GB at 16K context. His spoken concurrency example associates about 42 GB with 4K context and 80 users. The supplied description instead associates 42 GB with 16,000 tokens and 80 users; those figures are inconsistent. The per-token estimate and spoken 4K example support the central mechanism: independent concurrent sequences multiply KV demand, and a 24 GB GPU cannot accommodate a 42 GB cache.

GPU capacity divides into model weights, runtime overhead, and the remaining space available for KV storage. The weights are fixed for a loaded model; overhead is treated as approximately fixed in this simplified accounting. The notebook gives about 14.6 GB for the model at 16-bit precision. Once those allocations are accounted for, longer contexts and more users compete for the same remaining memory. Supporting 160 users, for example, requires a shorter context than supporting fewer users under otherwise unchanged conditions.

12:3212:39
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

12:16 · section reference included

Prefill spends compute; decode repeatedly moves data

Selected presentation frame from Deep dive on LLM Inference at Scale — Harshul Jain, Audible & Tanmay Sah, Independent AI Researcher at 1660 seconds
Prefill spends compute; decode repeatedly moves data

Prefill processes the prompt, builds its keys and values, and computes attention relationships across its tokens. This is matrix-heavy work with substantial computation, so Jain describes it as compute bound. In the workshop's simplified timeline, prefill determines time to first token: more input tokens require more projections and attention work before the first output appears.

Decode generates subsequent tokens one after another. Each step computes attention for the new token while needing the preceding tokens' key and value representations. Compared with processing an entire prompt, this provides less computation per step. The time between successive outputs is inter-token latency, the fourth metric introduced in the workshop. It captures how quickly a response continues after its initial wait.

To explain the memory bottleneck, Jain distinguishes large GPU memory from smaller, faster shared memory. In his high-level account, computation loads chunks into shared memory, performs the math, and writes results back. Decode repeats this process for successive tokens. Its speed can therefore be limited by how quickly weights and KV data reach the computation, even when the GPU has additional arithmetic capacity.

Arithmetic intensity expresses this distinction as floating-point work per byte transferred. Decode moves weights and preceding KV vectors to compute an output for one new token, giving it relatively low arithmetic intensity. Prefill performs more computation over the transferred data and has higher intensity. The roofline discussion uses this relationship to distinguish bandwidth-limited work from compute-limited work.

The timing demonstration shows prefill duration increasing with input length. Decode timings remain nearer an average after excluding cold-start effects, but Jain cautions that they are not constant. A longer history still means more keys and values must be pulled from memory, so decode latency can also increase with context.

20:5620:59
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

20:33 · section reference included

Capacity must satisfy a latency target

Selected presentation frame from Deep dive on LLM Inference at Scale — Harshul Jain, Audible & Tanmay Sah, Independent AI Researcher at 2169 seconds
Capacity must satisfy a latency target

A memory-based concurrency estimate divides available KV memory by KV storage per user. With the model, GPU, and KV precision fixed, context length and concurrent users become the adjustable variables. Increasing concurrency requires reducing context at the memory limit, and that reduction may harm answer quality by limiting the information a request can carry.

Fitting the maximum number of users does not mean serving them acceptably. A business also has a latency service-level objective. More users and larger batches can increase decode time and affect TTFT, making useful capacity lower than the memory ceiling. Jain frames the resulting decision around quality, latency, and throughput. Premium chat favors quality and responsiveness, accepting fewer users per GPU; asynchronous agent work can favor quality and aggregate throughput because its tasks already run over longer periods.

The capacity calculator combines GPU memory, bandwidth, compute capacity, and hourly cost with model and workload choices. Jain selects a 7-billion-parameter model at FP16 and begins by fixing the requirement that matters most: latency for premium chat, or a minimum batch size for asynchronous work. His chat example considers a 10-millisecond latency target while preserving context for quality. These are illustrative calculator inputs, rather than a demonstrated service guarantee.

Hourly price alone can lead to the wrong GPU choice. A more expensive device may deliver a lower cost per million tokens if its useful throughput is sufficiently higher. The calculation must therefore follow the workload constraints: estimate the concurrency and context that remain viable at the required latency, then compare the resulting token economics. Jain emphasizes that inaccurate capacity estimates undermine this comparison.

29:0429:07
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

28:35 · section reference included

Quantization reduces the weight allocation

Selected presentation frame from Deep dive on LLM Inference at Scale — Harshul Jain, Audible & Tanmay Sah, Independent AI Researcher at 2221 seconds
Quantization reduces the weight allocation

Sah introduces two deliberately fictional teaching algorithms. The ostrich algorithm stands for waving through an assumption, such as treating compression as lossless. The world cup algorithm stands for dividing a large problem into smaller pieces and carrying useful results forward. Their role is to make the optimization decisions memorable; they are not numerical methods or evidence that an assumption is valid.

His weight-sizing example asks how a 120-billion-parameter model could fit on one 80 GB H100. At two bytes per parameter, the illustrative weight allocation is 240 GB. Reducing precision to eight bits gives approximately 120 GB, which still does not fit. Sah then describes a four-bit representation with an approximate 65 GB footprint. The example shows why the required compression ratio follows from the memory budget, although the exact model representation is presented tentatively.

For Mistral 7B, Sah discusses INT8, INT4, and NF4 alternatives to 16-bit weights. Fewer bits reduce storage, but preserved quality is an assumption that must be tested. He calls for external benchmark evaluation and distinguishes post-training quantization from incorporating quantization during training or fine-tuning. The decision is therefore both a sizing exercise and an assessment of the numerical changes the workload can tolerate.

38:1938:27
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

37:01 · section reference included

Attention variants change how much KV state is needed

Selected presentation frame from Deep dive on LLM Inference at Scale — Harshul Jain, Audible & Tanmay Sah, Independent AI Researcher at 2608 seconds
Attention variants change how much KV state is needed

Sah uses a 4096-by-4096 matrix to illustrate splitting work. Dividing its columns into groups of 128 produces 32 blocks, providing an intuition for multiple attention heads and parallel computation. The example explains decomposition; the subsequent memory savings come from changing how many key and value representations those query heads use.

Multi-query attention represents the extreme of sharing one KV set across multiple query heads. Sah describes this informally as retaining one block instead of 32, assuming that queries can use the shared representation. Grouped-query attention takes a middle position: query heads form groups that share KV representations within each group. This reduces KV storage without taking sharing to the single-set extreme. The proposed quality preservation remains something to establish for the model and task.

Multi-head latent attention offers another route: compress key and value information into a latent vector and reconstruct the representations needed for attention. Sah notes that positional information complicates this approach, particularly its interaction with rotary positional encoding, or RoPE. The explanation identifies the need to preserve a positional component but does not derive the reconstruction or positional treatment in full.

Sparse attention changes which tokens receive attention. Instead of attending to the entire preceding sequence, the proposed strategy attends to selected important tokens. This targets the amount of attention work, rather than only the size of its stored representations. Sah presents it as an evolving direction; the workshop does not establish how those important tokens are selected or quantify the resulting quality tradeoff.

43:1843:28
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

42:34 · section reference included

FlashAttention uses tiles to reduce intermediate memory traffic

FlashAttention addresses repeated movement between large GPU memory and the computation. Sah contrasts a sequence of calculations and writes back to memory with processing smaller tiles of the query and key matrices in fast local memory. Keeping running state for online softmax allows attention to proceed tile by tile. The important mechanism is that breaking up the computation also changes where intermediate work stays, reducing the need for repeated large-memory transfers.

The storage comparison gives a concrete grouped-query example: reducing 32 KV heads to eight yields fourfold compression of that KV allocation. Latent-attention savings depend on the architecture, including layer count and latent dimensions. Sah gives a much larger preliminary savings estimate while expressing uncertainty about the dimensions, so it is not established here as a general compression ratio.

The attention scorecard remains qualitative. Sah describes grouped-query quality as close to multi-head attention while stressing that the use case matters, and describes single-set multi-query sharing as a stronger quality compromise. He also briefly introduces sliding windows, linear attention as summarizing information before lookup, and Mamba as a state-space model. These alternatives receive an orientation rather than a detailed implementation or measured comparison.

48:0048:29
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

48:00 · section reference included

Memory savings do not establish throughput gains

Selected presentation frame from Deep dive on LLM Inference at Scale — Harshul Jain, Audible & Tanmay Sah, Independent AI Researcher at 3365 seconds
Memory savings do not establish throughput gains

Jain returns to the quantization notebook. After a weight-download delay, he reports approximately 15 GB at FP16 and 7.5 GB with INT8, illustrating a twofold reduction in weight memory. The freed capacity can support longer KV histories or additional concurrent users. The four-bit discussion gives varying approximate footprints, so the stable conclusion is the direction of the weight reduction rather than a single exact four-bit measurement.

The plot that follows contains theoretical throughput numbers rather than a throughput test performed in this demonstration. Jain also notes that some benchmarks they studied showed lower throughput with INT8 compression. Smaller storage therefore cannot be taken as proof of faster execution: it expands memory capacity, while actual serving speed remains an empirical question.

The attention notebook encounters a GPU-detection problem, limiting the live demonstration. Jain nevertheless makes a substantive correction to the earlier latent-attention calculation: the claimed 50–56-fold saving should be 14-fold for their example. The previous computation omitted the number-of-layers multiplier. This corrected figure is an example-specific storage comparison with multi-head attention, rather than a universal latent-attention ratio.

53:4254:17
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

53:12 · section reference included

KV caching, paging, batching, and prefix reuse

Selected presentation frame from Deep dive on LLM Inference at Scale — Harshul Jain, Audible & Tanmay Sah, Independent AI Researcher at 3837 seconds
KV caching, paging, batching, and prefix reuse

The serving discussion begins with the waste in recomputing earlier tokens' keys and values during an uncached generation loop. A KV cache retains those vectors and references them in later steps, trading memory for avoided computation. The improvement concerns reuse of projections already computed; the new token still needs access to the preceding KV state for attention.

Paged attention addresses allocation waste. Jain's toy example reserves 2 KB for a request that uses only 1 KB, wasting half the allocation. Requiring contiguous storage can also prevent useful free space from accommodating another request. The operating-system analogy separates logical order from physical placement: a sequence's KV state appears logically contiguous while mapping to different physical memory blocks. Blocks are allocated as new tokens require them, allowing memory to follow actual request growth.

Continuous batching addresses wasted scheduling capacity. In a fixed batch, new work waits until all its requests finish, even when some finish earlier. Continuous batching allows new requests to enter as capacity becomes available, keeping more useful work on the GPU. Paging concerns where state resides; batching concerns when requests can use the computation.

Prefix caching extends reuse across requests that share an initial token sequence, whereas the basic KV cache reuses state across generation steps within a request. KV quantization reduces the storage used by the cached vectors themselves. The resulting capacity can accommodate more tokens, longer contexts, or more requests; the workshop does not demonstrate that quantizing those vectors automatically improves answer quality. Jain presents these serving mechanisms as capabilities available through vLLM rather than features practitioners need to rebuild.

1:00:361:00:38
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

1:00:14 · section reference included

The serving benchmark separates speed from cache footprint

Selected presentation frame from Deep dive on LLM Inference at Scale — Harshul Jain, Audible & Tanmay Sah, Independent AI Researcher at 4171 seconds
The serving benchmark separates speed from cache footprint

The benchmark keeps Mistral 7B as the model and sends a set of prompts through successive server configurations. Helper functions check server readiness, collect metrics, and measure KV usage. Jain says the full process takes around an hour because configurations require stopping servers, restarting them, and loading weights. These are reported benchmark results rather than a full live rerun.

On an H100, the plain Hugging Face baseline delivers around 51 tokens per second. Jain also reports first-token and inter-token latency values, but their units are not stated in the spoken passage. Moving to the default vLLM server, with paged attention, continuous batching, and KV caching, produces nearly 15 times the throughput in their comparison. He reports higher TTFT and lower inter-token latency, illustrating that a large throughput gain need not improve every latency measure.

Adding prefix caching raises throughput further and reduces TTFT while leaving inter-token latency approximately unchanged in the reported test. The description of its KV-usage changes is less definite, so it does not establish a precise memory benefit. Adding KV quantization leaves throughput and both latency measures approximately similar but lowers KV usage. This is a useful distinction: an optimization can improve the memory footprint without producing an immediate speedup on the tested workload.

The speculative-decoding configuration likewise produces approximately similar results in Jain's summary, with somewhat lower KV usage. Its inclusion does not establish a general decoding speedup. It sets up the next discussion of why draft generation and verification depend on how well their predictions agree.

1:06:051:06:08
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

1:06:05 · section reference included

Speculative decoding depends on accepted drafts

Selected presentation frame from Deep dive on LLM Inference at Scale — Harshul Jain, Audible & Tanmay Sah, Independent AI Researcher at 4464 seconds
Speculative decoding depends on accepted drafts

Sah explains speculative decoding as drafting several tokens with a smaller model, then asking the larger model to decide how many to accept. His example proposes four or five tokens per draft. The loop repeats, attempting to advance generation by more than one token at a time. Agreement between the draft and verifying model is central: draft work provides little benefit when few proposed tokens are accepted.

He suggests that predictable domains, including repeated code syntax, may suit this approach, but says his own testing did not find basic speculative decoding useful. That is a personal, setup-dependent result rather than a demonstration that the method never works. The workshop does not supply acceptance rates or a detailed cost breakdown that would explain the outcome quantitatively.

The related methods change how candidates are produced. Sah describes self-speculation using an auxiliary head within the main model, EAGLE using a trained predictor informed by the main model's internal features, and Medusa proposing tokens in parallel. He personally favors EAGLE over the alternatives discussed. These are brief mechanism sketches, without enough comparative measurements to establish a ranking across workloads.

1:12:101:12:12
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

1:11:32 · section reference included

Branching prefixes and hardware-specific engines

Selected presentation frame from Deep dive on LLM Inference at Scale — Harshul Jain, Audible & Tanmay Sah, Independent AI Researcher at 4572 seconds
Branching prefixes and hardware-specific engines

Sah contrasts hash-based prefix lookup with a radix-tree approach. Hash lookup reuses stored KV state when the relevant input matches; changing a word or letter can break that match. A radix tree represents shared prefixes and their branches, compressing paths that do not branch. Its value is reuse of the unchanged beginning of related sequences, rather than treating differently worded prompts as interchangeable.

Agent loops make shared prefixes especially relevant. Sah gives the example of a software-engineering role prompt repeated 200 times as a workflow loops. Shared instructions and related continuations create opportunities to retain reusable state while representing divergent branches separately. He identifies SGLang as using radix-tree prefix caching for this kind of reuse.

TensorRT-LLM enters as another inference engine. Sah distinguishes the broader TensorRT SDK from the LLM-serving engine and emphasizes its connection to NVIDIA hardware. Its approach includes optimizing layers and execution at the hardware level. This adds another engine-selection consideration: the fit between an execution stack and its target hardware.

1:14:331:14:39
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

1:14:29 · section reference included

Standard requests and agentic branching produce different comparisons

Selected presentation frame from Deep dive on LLM Inference at Scale — Harshul Jain, Audible & Tanmay Sah, Independent AI Researcher at 4720 seconds
Standard requests and agentic branching produce different comparisons

The presenters compare vLLM and SGLang on an H100 using questions from ShareGPT. For this standard request workload, they report no statistical difference between the engines, with similar requests per second, TTFT, and latency. The passage does not give the statistical procedure, sample size, or uncertainty intervals, so the finding applies to their reported comparison rather than proving general equivalence.

Their agentic test changes the interaction pattern. A first turn asks for a proposal to solve traffic congestion in a city. A second turn asks the model to review the proposal and rate it from 1 to 10, and this two-turn pattern repeats. Standardized prompts and context create the branching workload they want to test. Sah reports SGLang performing three to four times better in that setup, while explicitly warning that different setups may yield different results. The spoken summary does not specify one exact metric for that multiplier.

Jain's recommendation is to begin with vLLM for a standard API workload and consider SGLang when agentic behavior makes the default unsatisfactory. He also points to a separate 120-billion-parameter-model comparison that includes TensorRT-LLM, but does not report its numerical results here. Engine choice consequently remains tied to the request pattern, model, and hardware rather than a single winner for every deployment.

1:17:271:17:30
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

1:17:27 · section reference included

Choose a baseline, then deepen the bottleneck that matters

The closing engine survey mentions NVIDIA Dynamo in connection with agentic session routing, a simple Hugging Face path without a server, and research into multimodal serving. Jain then returns to the deployment sequence: establish a baseline, choose a model that meets the use case, reduce its memory footprint where appropriate, and use a serving engine to obtain the required throughput. He cautions against treating the small workshop model as an automatic production choice.

The next level of study concerns KV eviction, cache compression, and hybrid memory. These topics extend the question from how to retain reusable state to which state should remain resident and how it should be stored. Jain urges practitioners to connect each proposed solution to the problem it actually solves, then determine whether that problem exists in their own workload. The workshop names these directions without deriving their policies or implementation tradeoffs.

Distributed inference is left as a separate substantial subject, requiring its own treatment of internals and hands-on work. The presenters describe a proposed advanced workshop, invite feedback and expressions of interest, and close by offering to discuss questions offline. The recording therefore ends with a clear boundary: it builds the foundations of inference optimization, while distributed execution and deeper cache engineering remain further work.

1:22:271:22:30
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

1:22:27 · section reference included

Read the complete timestamped transcript
  1. 0:13

    Uh so good afternoon everyone. Um my

  2. 0:16

    name is Hershel Jan and he is Tanisha.

  3. 0:20

    Uh and we would like to welcome you all

  4. 0:22

    in this two hours workshop on the LLM

  5. 0:25

    inference. Uh so the goal of this

  6. 0:28

    workshop is to understand this domain

  7. 0:32

    from the first principles uh dive deeper

  8. 0:35

    into it and like understand what's going

  9. 0:38

    on throughout the industry.

  10. 0:41

    Uh a bit of background about us. So I am

  11. 0:45

    a senior software engineer at Audible.

  12. 0:48

    uh have been building MLA data platforms

  13. 0:51

    for the past five years and on the sides

  14. 0:54

    I have been writing this opensource

  15. 0:56

    handbook on LLM inference

  16. 0:59

    and Tanme he is the senior quantitative

  17. 1:03

    modeler at XAN cup bank corporation he

  18. 1:06

    recently completed his PhD and he has

  19. 1:09

    been actively doing research in the

  20. 1:12

    agent verifiers and the world models

  21. 1:18

    Uh so a quick show of hands here. Uh Vu

  22. 1:22

    here is like brand new to the LLM

  23. 1:24

    inference.

  24. 1:27

    Okay, great. And Vu here has like

  25. 1:29

    deployed these models in production.

  26. 1:33

    They have been tuning it. They have been

  27. 1:35

    serving the production traffic.

  28. 1:38

    Okay, great.

  29. 1:41

    So this workshop is targeted towards the

  30. 1:44

    beginner and the intermediate level. U

  31. 1:48

    and all of the slides and exercises they

  32. 1:50

    are in the repo. I will share that soon.

  33. 1:55

    Here is the quick agenda for the

  34. 1:57

    workshop. We will start with the problem

  35. 2:00

    statement. We will try to understand few

  36. 2:02

    of the pain points around LLM inference.

  37. 2:06

    uh then we understand what causes those

  38. 2:08

    pain points and build our foundations

  39. 2:10

    from there.

  40. 2:12

    Then we will dive into like two kind of

  41. 2:15

    the optimizations that we do like the

  42. 2:17

    model optimizations and the serving

  43. 2:19

    optimizations.

  44. 2:21

    uh and then we start learning about

  45. 2:23

    different serving engines that are

  46. 2:25

    available to deploy our LLM inference

  47. 2:29

    solutions in production and we will

  48. 2:31

    showcase some benchmarks and the

  49. 2:33

    decision chart on like which engine to

  50. 2:36

    use.

  51. 2:40

    Cool. So to understand the pain points

  52. 2:43

    first we need to know what is like LLM

  53. 2:46

    inference. So, and probably a lot of us

  54. 2:49

    already know this. Um, but yeah,

  55. 2:52

    anything that you ask your AI to do like

  56. 2:55

    whether it be generate a video, audio,

  57. 2:58

    analyze any text, uh, analyze your

  58. 3:01

    medical reports or like your tax bills,

  59. 3:04

    all of that is like an LLM inference.

  60. 3:08

    And this market is like approximately

  61. 3:11

    $23 billion today.

  62. 3:15

    uh semi analysis recently shared that if

  63. 3:18

    you want to model like a Google search

  64. 3:20

    queries with LLMs, you need like a

  65. 3:23

    profit drain of like $36 billion

  66. 3:27

    and query cost has to be less than 0.5

  67. 3:31

    cents to keep your search business

  68. 3:33

    profitable.

  69. 3:35

    On the other hand, the business insider

  70. 3:38

    mentioned like your AI has to be put on

  71. 3:40

    diet

  72. 3:42

    and everyone has to start auditing and

  73. 3:44

    budgeting their token usage and all of

  74. 3:47

    this is happening. Why? Because your

  75. 3:50

    hardware is limited, compute is

  76. 3:52

    expensive, your inference is expensive

  77. 3:55

    and with the growing need of like more

  78. 3:58

    and more AI usage, this inference cost

  79. 4:00

    is rising more and more.

  80. 4:03

    So

  81. 4:05

    this stat, it's an old stat from the

  82. 4:08

    open AI, but it's still it's still true.

  83. 4:11

    So if you look at the like training cost

  84. 4:14

    of the GPT3, it was like around $4.6

  85. 4:17

    million. It was a one-time cost. But if

  86. 4:20

    you see the inference cost that has been

  87. 4:23

    like uh it's a recurring cost because

  88. 4:26

    it's a operating cost that scales with

  89. 4:28

    every user that comes in that every

  90. 4:30

    token that comes in every session that

  91. 4:32

    uh is being initiated on the like AI

  92. 4:39

    and there are only two ways to basically

  93. 4:42

    counter this. Uh one way is you reduce

  94. 4:45

    your token usage.

  95. 4:47

    um alternative is you should try to

  96. 4:50

    optimize your inference solutions as a

  97. 4:53

    inference service provider for your

  98. 4:56

    customers and for yourself. And so this

  99. 4:59

    um we have been seeing like lot and lot

  100. 5:02

    of like new solutions coming out every

  101. 5:04

    then and now. Um and so the idea would

  102. 5:08

    be like okay we will try to build those

  103. 5:10

    foundations that will help us understand

  104. 5:13

    and evaluate like whatever ships next.

  105. 5:17

    Um so yeah to get started like we will

  106. 5:21

    do a quick demo like it's a short demo

  107. 5:24

    of like what are the different pain

  108. 5:25

    points around inference

  109. 5:28

    u and so this is the repo uh I mean you

  110. 5:33

    can pull it or you can also open it on

  111. 5:35

    the GitHub

  112. 5:37

    uh it's called LLM inference at scale a

  113. 5:39

    bit of background here like four months

  114. 5:42

    back when I didn't knew anything on the

  115. 5:43

    LLM inference um I started learning it I

  116. 5:47

    saw like lot of resources were

  117. 5:48

    scattered. So we started putting it uh

  118. 5:51

    like all together in one place uh so

  119. 5:53

    that it could benefit people.

  120. 5:56

    Um yes. So let me actually get out of

  121. 6:00

    this slideshow mode and probably

  122. 6:04

    go into

  123. 6:08

    I will go to this extended mode.

  124. 6:13

    Um

  125. 6:16

    okay great.

  126. 6:19

    Uh yeah so in this uh repository if you

  127. 6:23

    see a readme file there is like a link

  128. 6:26

    to the slides. Uh so this it will be

  129. 6:29

    like this folder where you have like a

  130. 6:31

    pptx and there is like a benchmark

  131. 6:33

    report in there.

  132. 6:36

    uh you can always like download it and

  133. 6:39

    then for the demo purposes uh we have

  134. 6:42

    couple of Jupyter notebooks. Uh we have

  135. 6:44

    like collaborated with Moab who are the

  136. 6:47

    like Google collab alternative

  137. 6:50

    and what they basically provide you is

  138. 6:52

    like a free RTX 6000 GPU. It's a 100 GB

  139. 6:56

    V RAM GPU.

  140. 6:58

    So

  141. 6:59

    and we have like already set up these

  142. 7:01

    notebooks so that it becomes easy to

  143. 7:04

    like experiment with and like all of the

  144. 7:07

    assets and everything are preset for

  145. 7:09

    you. Uh

  146. 7:12

    so uh we will start with like a simple

  147. 7:15

    demo a

  148. 7:18

    probably

  149. 7:21

    let me just see

  150. 7:29

    Okay.

  151. 7:31

    Um yeah. So

  152. 7:35

    when it comes to the inference, you need

  153. 7:37

    to do an inference on a certain model,

  154. 7:40

    right? Uh for the workshop purposes, we

  155. 7:42

    are using a simple ML 7B model. Uh it's

  156. 7:46

    a small model of around 15GB in size. So

  157. 7:49

    we we are going to like load that into

  158. 7:51

    the GPU. So,

  159. 7:55

    and we would look like some of the GPU

  160. 7:57

    stats as well. So, we see like okay, we

  161. 7:59

    are working on the 6,000 Blackwell. Uh,

  162. 8:02

    and you might be thinking I'm not

  163. 8:03

    running the cells because I don't trust

  164. 8:05

    the Wi-Fi at conferences.

  165. 8:08

    So, yeah. So, I would probably be just

  166. 8:11

    going over the results uh that we kind

  167. 8:13

    of ran previously.

  168. 8:18

    Uh, yeah. So, we have like a GPU which

  169. 8:20

    is like 102GB.

  170. 8:23

    Uh now the first thing that comes to my

  171. 8:26

    mind is like what's my memory

  172. 8:27

    consumption looks like when I do the LLM

  173. 8:29

    inference. So I load this model

  174. 8:33

    uh and I see like okay I have like a 15

  175. 8:36

    GB here. So I have roughly like 87.5GB.

  176. 8:40

    And now when I do the like inference

  177. 8:43

    here

  178. 8:45

    uh what I notice is like the more the

  179. 8:48

    number of inputs I pass more is the

  180. 8:51

    memory that I need.

  181. 8:53

    uh and it's increasing slowly but it's

  182. 8:55

    still increasing. [snorts] So imagine

  183. 8:57

    like if you have a context length of

  184. 8:59

    like around 4,000 or 16,000 or 32,000

  185. 9:03

    uh tokens. Uh so this memory could like

  186. 9:06

    really grow big and it you could

  187. 9:08

    actually get like all of those out of

  188. 9:10

    memory issues.

  189. 9:13

    Uh so definitely this is like your

  190. 9:15

    problem one like your memory increasing

  191. 9:17

    with the increase in tokens. So in form

  192. 9:19

    of like a simple visualization it looks

  193. 9:21

    like this.

  194. 9:25

    The second problem that you would see is

  195. 9:27

    like

  196. 9:28

    the time to your first token it's very

  197. 9:31

    very slow. Uh we measure it by a metric

  198. 9:34

    called TTFT. It's a short short form of

  199. 9:37

    it. uh and when you try to like measure

  200. 9:41

    the TTFT uh with the like input size you

  201. 9:46

    would see like longer the context

  202. 9:49

    you would see like this uh TTFT being

  203. 9:52

    slow. So now there are two problems.

  204. 9:54

    Your memory increases with the token

  205. 9:56

    size. Your TTFT increases with the token

  206. 9:59

    size.

  207. 10:00

    Uh sorry not the token size, the context

  208. 10:02

    size.

  209. 10:06

    Uh and then the third is the like

  210. 10:08

    throughput. The throughput is like how

  211. 10:11

    many tokens can you serve per second and

  212. 10:14

    then how many users can you serve per

  213. 10:16

    second. So if you take a very very

  214. 10:18

    vanilla implementation on your local

  215. 10:20

    system

  216. 10:22

    uh it would be like very sequential. So

  217. 10:24

    if you send like five requests all those

  218. 10:27

    five requests would be catered like

  219. 10:29

    sequentially rather than parallelly.

  220. 10:32

    Uh and so like your request basically

  221. 10:36

    takes more time to complete if you have

  222. 10:38

    like multiple users.

  223. 10:41

    So these are the like three problems.

  224. 10:43

    There is a fourth one. I haven't

  225. 10:44

    described it here. probably we will

  226. 10:46

    build that intuition as we move forward.

  227. 10:50

    Uh but let's remember like these are the

  228. 10:52

    three problems the memory TTFT and the

  229. 10:55

    throughput.

  230. 10:58

    Cool. Uh I will go back to the slides.

  231. 11:07

    Okay, perfect.

  232. 11:15

    Uh so it should be this.

  233. 11:20

    >> Uh is it visible?

  234. 11:35

    Oh, you you need the

  235. 11:38

    Oh, okay. Workshop. Okay.

  236. 11:47

    Yeah. So, within that repository, if you

  237. 11:50

    see a workshop folder, you see that

  238. 11:53

    readme and then the readme has all the

  239. 11:55

    links, the slides and the demos.

  240. 12:04

    Uh, does that work?

  241. 12:09

    Okay, perfect.

  242. 12:16

    Okay. uh so let's start working through

  243. 12:18

    the foundations like let's start

  244. 12:20

    understanding

  245. 12:22

    uh what are the reasons behind those

  246. 12:24

    pain points and for that like we have to

  247. 12:27

    look at this inference pipeline

  248. 12:29

    um

  249. 12:32

    so we get like an input text uh that

  250. 12:35

    text could have like any number of words

  251. 12:39

    you convert those into the tokens so for

  252. 12:42

    simplicity you can assume one word equal

  253. 12:45

    to one token

  254. 12:47

    uh then you kind of convert them into

  255. 12:49

    like the embeddings and then you send it

  256. 12:51

    to the like transformers

  257. 12:54

    uh like there are 32 layers of

  258. 12:56

    transformers but that's specific to the

  259. 12:57

    Mistl 7B different models have different

  260. 13:00

    kind number of layers uh and then you

  261. 13:03

    generate a new token and that token

  262. 13:05

    basically goes back to the input then

  263. 13:07

    you generate another token and that

  264. 13:08

    keeps on going now in this entire

  265. 13:11

    pipeline you would see like 95% of your

  266. 13:15

    compute is like taken by these

  267. 13:17

    transformer layers. So it's worth

  268. 13:19

    looking at like what goes within this

  269. 13:21

    transformer layer.

  270. 13:25

    Within this transformer layer you would

  271. 13:26

    have like more layers. You have like a

  272. 13:29

    normalization layer, you have an

  273. 13:31

    attention layer, you have a feed forward

  274. 13:34

    layer and all.

  275. 13:35

    And attention layer is the one I think

  276. 13:38

    that has been very very famous.

  277. 13:40

    Attention is all you need paper. I think

  278. 13:42

    that's very well known. So attention is

  279. 13:45

    the most compute intensive layer and we

  280. 13:49

    need to understand what goes within that

  281. 13:51

    attention layer.

  282. 13:54

    So what does attention do? Attention uh

  283. 13:58

    so if you have an input text it needs to

  284. 14:00

    find the attention scores of every token

  285. 14:03

    with respect to all of the previous

  286. 14:04

    tokens.

  287. 14:06

    And to do that what it needs to do is

  288. 14:09

    like it needs to project every token

  289. 14:11

    into like a key query and the value

  290. 14:13

    space. So in like in a simpler terms

  291. 14:18

    just u understand this like if you have

  292. 14:22

    10 tokens then it needs like the 10

  293. 14:24

    different query key and the value

  294. 14:26

    vectors. If there are 100 tokens you

  295. 14:29

    would need 100 key and the value

  296. 14:30

    vectors. If there are thousand tokens

  297. 14:32

    you would need thousand key value

  298. 14:34

    vectors. And so like your number of the

  299. 14:36

    key and the value vectors they increase

  300. 14:38

    as you increase the input size.

  301. 14:44

    Uh and if you calculate the like KV size

  302. 14:48

    per token

  303. 14:50

    uh for a mist 7B it comes out to be 131

  304. 14:53

    KV. Uh this is because like

  305. 14:57

    uh you have two vectors K and V. You

  306. 15:00

    have to multiply the size uh one vector

  307. 15:03

    is like 128 dimensions. you have to

  308. 15:05

    multi multiply it by 32 transformer

  309. 15:08

    layers and then you have to multiply it

  310. 15:10

    by the KV heads for ML 7B it's gate KV

  311. 15:15

    heads it's not like 32 because it uses a

  312. 15:18

    different kind of an attention mechanism

  313. 15:21

    u which we will talk about for sure but

  314. 15:25

    yeah so the KV size per token is like

  315. 15:29

    your 131 KB now imagine if you have 4K

  316. 15:33

    context uh So that size becomes like

  317. 15:35

    half a GB. Uh if you do like 16k context

  318. 15:40

    that size becomes 2.1 GB. Uh now

  319. 15:44

    multiplay by the users like assume you

  320. 15:46

    can serve multiple users together

  321. 15:50

    at the same time within that GPU you

  322. 15:53

    could have like 42GB with a 4K context

  323. 15:56

    and 80 users. Um and if your GPU is only

  324. 16:00

    like let's say 24GB, you are already

  325. 16:03

    running out of the memory. So you cannot

  326. 16:05

    serve that many users with that many

  327. 16:07

    context.

  328. 16:12

    To visualize this, look at a GPU memory.

  329. 16:15

    So the GPU memory has like a model

  330. 16:17

    weights which are pretty fixed. These

  331. 16:20

    are pre-trained weights. Uh there is

  332. 16:23

    like an overhead that is also fixed.

  333. 16:25

    that also like that changes but it does

  334. 16:27

    not change that much u overall you can

  335. 16:30

    assume it's fixed and then there is like

  336. 16:33

    a leftover memory so this leftover

  337. 16:36

    memory is what being used by your KB me

  338. 16:39

    like key and the value vectors so

  339. 16:44

    assume like you have a one user you can

  340. 16:48

    only serve that many key and the value

  341. 16:51

    vectors or that many tokens which can

  342. 16:54

    like fit in this entire 80GB uh like

  343. 16:58

    memory that is left.

  344. 17:02

    Uh

  345. 17:04

    so we can show this with a simple demo

  346. 17:07

    too. Uh

  347. 17:13

    okay, let me

  348. 17:18

    Okay, great.

  349. 17:23

    Okay, great.

  350. 17:25

    Uh, let me see if I can actually run

  351. 17:29

    this.

  352. 17:31

    What

  353. 17:36

    probably?

  354. 17:38

    Where the heck is this happening?

  355. 17:49

    Okay, great.

  356. 17:52

    Yeah. So you would see like the GPU is

  357. 17:55

    attached.

  358. 18:07

    So here we are just trying to confirm

  359. 18:09

    the like memory based on the maths and

  360. 18:11

    based on the intuition that we have

  361. 18:13

    built. So the model memory is like let's

  362. 18:16

    say if you have a 7 billion parameters

  363. 18:18

    you are doing a 16 bit precision your

  364. 18:21

    total memory comes out to be 14.6 GB

  365. 18:23

    with you can basically verify that with

  366. 18:26

    the maths. So if you do all that math

  367. 18:30

    that comes out to be the 14.6GB.

  368. 18:33

    Uh now comes the KVK and the KV size. So

  369. 18:38

    this KV size is like your 131 KB per

  370. 18:40

    token.

  371. 18:42

    Uh and if you do that maths and you try

  372. 18:45

    to like visualize this.

  373. 18:49

    [sighs]

  374. 18:52

    Oh, sure.

  375. 19:00

    Wait.

  376. 19:03

    Okay. And then let's just visualize

  377. 19:07

    this.

  378. 19:09

    Okay. Great.

  379. 19:11

    Uh yeah so this is the like a memory

  380. 19:14

    chart. So if you see like as your

  381. 19:17

    context increases your memory keeps

  382. 19:19

    increasing.

  383. 19:21

    Then another thing to realize is like as

  384. 19:24

    your users increase

  385. 19:26

    uh then also your memory increases. So

  386. 19:29

    if you want to serve like 160 users

  387. 19:33

    uh on a GPU you can support like uh you

  388. 19:37

    can only support like a lesser context

  389. 19:39

    length. So there is always a tradeoff

  390. 19:42

    between what context length you can

  391. 19:44

    serve versus how much cost you can save

  392. 19:48

    by like putting your multiple

  393. 19:51

    uh users or the concurrent users into

  394. 19:53

    like a single GPU. So you have to always

  395. 19:56

    take that tradeoff and and we will go

  396. 19:58

    through that like uh in couple of more

  397. 20:01

    slides.

  398. 20:06

    >> Uh can you repeat please?

  399. 20:14

    Uh I'm sorry I'm cannot hear you.

  400. 20:24

    >> Yeah.

  401. 20:33

    Cool.

  402. 20:35

    Uh okay. Great. So let me pull back.

  403. 20:41

    So that was like memory. Uh we need to

  404. 20:44

    understand uh why we had like uh slower

  405. 20:48

    time to first token

  406. 20:51

    uh when we increase the context length.

  407. 20:54

    So for that like we need to understand

  408. 20:56

    the two phases of inference and those

  409. 20:59

    phases are like the prefill and the

  410. 21:00

    decode phase. I think you would all seen

  411. 21:03

    like a lot of articles but we just

  412. 21:05

    wanted to explain it. Uh so when you

  413. 21:09

    send like a lot of uh like when you send

  414. 21:11

    these input tokens

  415. 21:14

    what you want to do is uh you want to

  416. 21:16

    build those key and the value vectors

  417. 21:18

    that I mentioned for all the tokens.

  418. 21:21

    Then you want to compute the attention

  419. 21:23

    scores of every token with respect to

  420. 21:26

    the previous token. All this operation

  421. 21:28

    that you do it's a very very metricsh

  422. 21:31

    heavy uh it's a very very compute heavy

  423. 21:34

    operation and we all know like the GPUs

  424. 21:37

    they are like very well suited for a

  425. 21:40

    heavy compute workload so we call like a

  426. 21:44

    prefill to be like a compute bound uh

  427. 21:47

    and it does take some time to complete

  428. 21:50

    so whatever time that this phase takes

  429. 21:52

    to complete that's your time to the

  430. 21:55

    first token

  431. 21:57

    So if if you have like a more input

  432. 21:59

    tokens, you have to generate more key

  433. 22:02

    value vectors. You have to do lot more

  434. 22:04

    attention math and because of that your

  435. 22:08

    TTFT becomes more more slower.

  436. 22:12

    Where is if once you generate one token

  437. 22:15

    you need to keep doing this to generate

  438. 22:17

    another tokens sequentially one after

  439. 22:20

    another. But in that process every time

  440. 22:23

    you have to build the key and the value

  441. 22:26

    vectors of all the previous tokens

  442. 22:29

    which is same as prefill like you were

  443. 22:31

    building key value vectors there also

  444. 22:33

    here also but in decode phase you are

  445. 22:36

    only computing the attention math for

  446. 22:38

    the new token

  447. 22:41

    and that is why it's a very less it's

  448. 22:44

    lesser compute oriented

  449. 22:46

    and it's also called as memory bound. We

  450. 22:48

    will see it shortly why it's called as

  451. 22:50

    memory bound.

  452. 22:54

    So in a classic timeline you would see

  453. 22:58

    prefill and decode phase like this. So

  454. 23:01

    time taken by prefill that's your time

  455. 23:03

    to first token and then your time taken

  456. 23:06

    by every decode step that's your

  457. 23:10

    uh basically your inter token latency.

  458. 23:13

    So that's like the fourth metric

  459. 23:16

    uh that you need to worry about like

  460. 23:19

    what's the time being taken by your

  461. 23:21

    decode step.

  462. 23:25

    Okay, cool. Uh

  463. 23:28

    now why why does the like decode step or

  464. 23:32

    why does decode takes time and why it's

  465. 23:36

    being called as like a memory bound

  466. 23:38

    operation? Let's try to understand that.

  467. 23:40

    uh to understand that we need to look at

  468. 23:44

    how the metrics map basically works on

  469. 23:46

    the GPU on a high level. So GPU has two

  470. 23:49

    kind of memories. You have a high

  471. 23:51

    bandwidth memory. You have a shared

  472. 23:54

    memory.

  473. 23:56

    So the high bandwidth memory is a larger

  474. 23:58

    size but a lower me like lower

  475. 24:00

    bandwidth.

  476. 24:02

    By lower bandwidth I mean like you can

  477. 24:04

    transfer data out of it at a lower rate

  478. 24:07

    compared to the shared memory. So the

  479. 24:09

    shared memory is smaller in size but it

  480. 24:12

    has a very very high bandwidth. Uh that

  481. 24:15

    means you can transfer data in and out

  482. 24:17

    of it with a very first thing. So when a

  483. 24:20

    when you have to do a metric math so you

  484. 24:23

    have to pick the data in chunks from the

  485. 24:26

    high bandwidth memory you have to put it

  486. 24:28

    into the shared memory.

  487. 24:31

    Do that math write back the result into

  488. 24:33

    the high bandwidth memory.

  489. 24:37

    uh for the prefill phase when you have

  490. 24:42

    to do this you have to do this matrix

  491. 24:45

    math only once but for the decode phase

  492. 24:48

    you have to do this metric math uh like

  493. 24:53

    uh again and again because you're

  494. 24:55

    generating each and every token

  495. 24:57

    sequentially

  496. 24:59

    and so like you it doesn't matter like

  497. 25:02

    how fast is your decode

  498. 25:05

    because now you can transfer your data

  499. 25:08

    out of the high bandwidth memory into

  500. 25:11

    the S shared memory at a certain speed

  501. 25:14

    because you are limited by the high

  502. 25:16

    bandwidth memory bandwidth speed

  503. 25:19

    and so that governs your like token

  504. 25:22

    sealing like at what rate can you

  505. 25:24

    actually generate tokens out of the

  506. 25:27

    decode step.

  507. 25:32

    If you look at this in the roof line

  508. 25:35

    plot

  509. 25:37

    uh so there is a left section which is

  510. 25:41

    called to be a memory bound.

  511. 25:43

    Mathematically it's governed by the

  512. 25:45

    arithmetic intensity.

  513. 25:47

    Arithmetic intensity is the number of

  514. 25:50

    flip-flop operations that you perform

  515. 25:52

    per bite of data being transferred. So

  516. 25:55

    for the decode step

  517. 25:58

    uh decode step since you are

  518. 26:01

    transferring lot of data like the key

  519. 26:04

    and the value vectors of the all the

  520. 26:06

    previous tokens the model weights but

  521. 26:08

    you are doing the like less computation

  522. 26:10

    because you're computing attention math

  523. 26:12

    for only one token. Uh so it's

  524. 26:16

    arithmetic intensity is very low but for

  525. 26:19

    a prefill phase you are transferring the

  526. 26:21

    data once but then like you are doing

  527. 26:25

    this heavy computation and so it's

  528. 26:28

    arithmetic intensity is very high. So

  529. 26:30

    now you know like in terms of

  530. 26:32

    mathematics like why the computer like

  531. 26:36

    why the arithmetic intensity of prefill

  532. 26:38

    is very high compared to your decor.

  533. 26:43

    Uh [snorts]

  534. 26:44

    okay

  535. 26:46

    so this is like another small small

  536. 26:49

    demo. Uh

  537. 26:52

    every time I have to Okay.

  538. 26:57

    Okay, great.

  539. 27:00

    I hope this is already running. So yeah,

  540. 27:03

    again we are loading the model.

  541. 27:07

    Now this is the like the prefill cost.

  542. 27:10

    So what we are basically doing is uh we

  543. 27:12

    are getting the like um the input uh

  544. 27:15

    text and then we are trying to generate

  545. 27:18

    this um the prefill step the amount of

  546. 27:22

    time it takes. We see like as we

  547. 27:24

    increase the like size of the input

  548. 27:26

    tokens this prefill is increasing. So

  549. 27:29

    you and this is the reason why your TDF

  550. 27:32

    increases

  551. 27:34

    and then like your decode time. So the

  552. 27:37

    decode time is like on average it stays

  553. 27:40

    about the same. Uh and so if it is like

  554. 27:44

    assuming like you ignore the like cold

  555. 27:46

    start your decode time is like

  556. 27:48

    approximately around the average line.

  557. 27:50

    it it it it is still impacted by like u

  558. 27:56

    the input size. It's not like it's a

  559. 27:58

    constant uh time and it is because it

  560. 28:02

    still needs to pull the key and the

  561. 28:03

    value vectors from the memory for all

  562. 28:05

    the previous tokens. So there is still

  563. 28:08

    like uh that uh basically small increase

  564. 28:12

    in time that you would see with the

  565. 28:14

    decode step. And then this is the like

  566. 28:17

    classic uh roof line plot.

  567. 28:21

    Uh okay.

  568. 28:27

    Presentation.

  569. 28:31

    Okay. Five. Okay. Great.

  570. 28:35

    Okay. So

  571. 28:38

    now now let's try to understand like uh

  572. 28:41

    the throughput dimension. You want to

  573. 28:44

    understand how many users you can

  574. 28:46

    actually serve and I think we saw like a

  575. 28:49

    diagram of the GPU memory where we saw

  576. 28:52

    okay there is some memory that is free

  577. 28:54

    for the key and the value vectors to

  578. 28:55

    grow.

  579. 28:57

    So assume like you have just a single

  580. 29:00

    user

  581. 29:02

    uh

  582. 29:04

    what's the total KV size that you have

  583. 29:07

    you can basically support it's defined

  584. 29:09

    by your context limit.

  585. 29:12

    uh the max users that you can support is

  586. 29:15

    like whatever is your GPU uh

  587. 29:18

    availability like whatever is the memory

  588. 29:20

    that is available in the GPU you divide

  589. 29:22

    it by the key and the value size per

  590. 29:24

    user uh and when you do that like it

  591. 29:28

    comes out to be like your the concurrent

  592. 29:30

    users.

  593. 29:33

    Now assume like your GPU is fixed, your

  594. 29:38

    model is fixed.

  595. 29:40

    Uh

  596. 29:41

    so

  597. 29:43

    your KV size per token is fixed. There

  598. 29:46

    are only two dimensions that are left

  599. 29:48

    here which is context and your

  600. 29:51

    concurrent users.

  601. 29:53

    If you want to serve more concurrent

  602. 29:55

    users, you have to reduce the context

  603. 29:57

    length. If you reduce the context

  604. 29:59

    length, you could impact your quality.

  605. 30:02

    Uh so these are the two dimensions right

  606. 30:05

    now that we are trading off.

  607. 30:09

    Then if we but can you actually serve

  608. 30:12

    the like max number of concurrent users?

  609. 30:17

    Uh in an ideal world probably not

  610. 30:20

    because

  611. 30:22

    every business has like a latency SLO

  612. 30:25

    that we have to meet.

  613. 30:28

    So

  614. 30:30

    if you remember like in the decode step

  615. 30:32

    I said the time for the decode still

  616. 30:35

    increases if you have more inputs.

  617. 30:38

    It also increases if you have more

  618. 30:39

    users.

  619. 30:41

    So ultimately

  620. 30:44

    uh your inter token latency also gets

  621. 30:47

    impacted

  622. 30:49

    if you have like a higher batch size and

  623. 30:51

    your TTF also gets impacted. So now

  624. 30:54

    there is a third dimension you have to

  625. 30:56

    worry about which is like your latency.

  626. 30:58

    So the three dimensions that you have is

  627. 31:01

    like a quality latency and the

  628. 31:03

    throughput. So it comes out to be like

  629. 31:05

    this trade-off triangle where you have

  630. 31:08

    to choose between the two. So for a

  631. 31:12

    premium chat application

  632. 31:15

    you would want to prioritize definitely

  633. 31:17

    the quality and you want to prioritize

  634. 31:19

    the like the latency. You would not want

  635. 31:22

    your users to wait infinitely for the

  636. 31:25

    like or like not infinitely but probably

  637. 31:28

    for the larger latency.

  638. 31:31

    You can always sacrifice the number of

  639. 31:33

    users you can support on the GPU and

  640. 31:35

    probably take that costed being more

  641. 31:38

    customers

  642. 31:40

    in form of like and and like if you

  643. 31:43

    consider like an agent uh sorry the

  644. 31:46

    async agent workload you would want to

  645. 31:49

    like prioritize definitely quality and

  646. 31:50

    the throughput

  647. 31:52

    uh because these are the longunning

  648. 31:55

    tasks

  649. 31:56

    uh and you would want to like serve as

  650. 31:59

    many as concurrent tasks. fast as

  651. 32:01

    possible but with a very very higher

  652. 32:03

    quality.

  653. 32:07

    And often like we think like okay if the

  654. 32:11

    GPU is like a very expensive GPU

  655. 32:15

    uh that might not be a good fit for us.

  656. 32:19

    Uh but it turns out that could actually

  657. 32:21

    serve you the lowest cost per million uh

  658. 32:24

    tokens.

  659. 32:27

    Uh but you really have to trust your

  660. 32:30

    kind of calculations on the max users

  661. 32:33

    that you want and like uh you really

  662. 32:36

    have to make those estimations uh

  663. 32:39

    correctly.

  664. 32:43

    Uh

  665. 32:49

    so we do have like uh

  666. 32:55

    let me just

  667. 32:59

    Where is this?

  668. 33:02

    Okay, great. So, for the capacity

  669. 33:05

    calculator, uh there is like a link to

  670. 33:08

    the collab because I was facing certain

  671. 33:11

    issues with molab. I had to migrate out

  672. 33:13

    the wall widget library and I didn't

  673. 33:16

    have time. So, being lazy, I just picked

  674. 33:19

    collab there. Uh apologies to Moab.

  675. 33:25

    Uh

  676. 33:27

    so my VR is connected.

  677. 33:35

    Okay.

  678. 33:46

    Wi-Fi probably.

  679. 33:51

    Okay. Great.

  680. 34:02

    So what we have done over here is we

  681. 34:04

    have like shaded some like the GPUs with

  682. 34:07

    their V RAMs, bandwidths, the flip-flops

  683. 34:10

    and the cost per hours. Um

  684. 34:14

    then we kind of like built this simple

  685. 34:17

    uh like uh capacity calculator. This is

  686. 34:20

    just a KV visualizer uh where you kind

  687. 34:23

    of like when you increase the number of

  688. 34:25

    tokens uh you see like your KV size it

  689. 34:28

    increases and when you increase the

  690. 34:31

    number of users your size is like

  691. 34:33

    increasing at a much faster rate

  692. 34:37

    and then

  693. 34:40

    in this capacity calculator uh

  694. 34:46

    let it run.

  695. 34:49

    So we have like a model which we which

  696. 34:52

    is like a 7 billion parameter model that

  697. 34:55

    we selected.

  698. 34:58

    We set the like precision to be FP16. Uh

  699. 35:01

    now we decide the way we basically go by

  700. 35:04

    the GPU decision is you have to decide

  701. 35:08

    what's your like you have to fix one

  702. 35:11

    dimension first which you care about the

  703. 35:13

    most.

  704. 35:15

    for premium chat I mentioned like

  705. 35:17

    latency is definitely the one

  706. 35:21

    uh and then like for the async workloads

  707. 35:23

    the batch the minimum batch size that

  708. 35:25

    you want to serve for from like a single

  709. 35:28

    GPU that is the second dimension so you

  710. 35:31

    want to fix these first so I will go

  711. 35:34

    about like in a premium chat application

  712. 35:38

    uh

  713. 35:39

    so I can go ahead with like 10

  714. 35:41

    milliseconds latency a minimum batch

  715. 35:45

    size I don't care like I can so I'm okay

  716. 35:47

    with like probably two

  717. 35:50

    uh

  718. 35:53

    okay so probably with the seven

  719. 35:56

    concurrent users on a single GPU and

  720. 35:59

    then like my context limit is very

  721. 36:01

    important to me because I want to focus

  722. 36:03

    on the quality as well

  723. 36:06

    uh and so like I do see like some of the

  724. 36:09

    GPUs so the H18GB

  725. 36:12

    it's like a $8 per hour but like am I

  726. 36:18

    300x is it? Yeah. So it's like around

  727. 36:21

    $10 per hour but if you do all that

  728. 36:26

    throughput math that we shared in the

  729. 36:28

    mathematics before you could find like

  730. 36:31

    your cost per million dollar tokens that

  731. 36:34

    could be very very that could be like

  732. 36:36

    lesser. So

  733. 36:39

    you need to do such calculations by

  734. 36:41

    fixing those dimensions and you need to

  735. 36:44

    decide your GPU to like reduce your kind

  736. 36:47

    of inference cost. This is at least the

  737. 36:50

    first step that you can take towards

  738. 36:51

    optimizing the inference.

  739. 36:56

    Okay, cool.

  740. 37:01

    So the next slide. So let me

  741. 37:08

    Okay, great.

  742. 37:10

    And so like now the next thing is about

  743. 37:13

    the model optimization. So we are now

  744. 37:15

    basically have built that foundation

  745. 37:17

    where we understood some of the pain

  746. 37:19

    points, reason behind those pain points,

  747. 37:21

    why those were happening

  748. 37:23

    um how we could like address that GPU

  749. 37:28

    capacity thing. We need to understand

  750. 37:30

    what can we do like what can we further

  751. 37:32

    do about it. So it it is about the model

  752. 37:36

    optimization and I think I would like to

  753. 37:38

    invite Tan I he can talk more about

  754. 37:40

    these model optimizations provided he

  755. 37:43

    has worked uh on this like during his

  756. 37:46

    research times

  757. 37:48

    okay I can control

  758. 37:53

    yeah here okay hi everyone uh mic check

  759. 37:58

    am I audible at last yeah okay so hi I'm

  760. 38:02

    Tesha I work as a senior quant modeler

  761. 38:05

    and also I am an AI researcher. My work

  762. 38:08

    focuses on a agent verification and

  763. 38:10

    right now building world models. So for

  764. 38:13

    this one model optimization

  765. 38:16

    before we start model optimization so I

  766. 38:19

    created a research template so that it

  767. 38:21

    will be easy for us to understand all

  768. 38:23

    these complex things. I so our template

  769. 38:27

    is simple. First we will identify the

  770. 38:29

    problem. Second step we will solve the

  771. 38:32

    problem using two algorithms. These are

  772. 38:34

    just fake algorithms. So first algorithm

  773. 38:36

    is called ostrich algorithm. Whenever we

  774. 38:40

    see uh just like ostrich whenever we see

  775. 38:42

    a problem ostrich put their head into

  776. 38:45

    the sand. So same thing we will do

  777. 38:47

    whenever we face a problem we will just

  778. 38:50

    ignore it. So this is an important

  779. 38:52

    algorithm we should follow. Second one

  780. 38:55

    is created it is called world cup

  781. 38:57

    algorithm. For example, we don't know

  782. 39:01

    who will win this FIFA World Cup. So,

  783. 39:03

    what organizers did, they uh break the

  784. 39:08

    48 teams into 12 groups, uh then round

  785. 39:12

    32. So, round 32 right now is currently

  786. 39:14

    going on. Uh then round 16, then

  787. 39:17

    quarterfinals, uh then semi-finals and

  788. 39:20

    finals. So what they are doing is that

  789. 39:24

    uh they are breaking it into a smaller

  790. 39:26

    problems and the useful results are

  791. 39:29

    moving forward. So same analogy or same

  792. 39:32

    algorithm we will use uh to understand

  793. 39:35

    this model optimization all those

  794. 39:37

    things. So yeah let's start. So I have

  795. 39:43

    one H100 GPU.

  796. 39:46

    I have to use this open-source model

  797. 39:49

    what is called GPTOSS

  798. 39:51

    120 billion parameter model. So right

  799. 39:55

    now I think it's so they have trained it

  800. 39:57

    on BF float 16 and weight is 240 GB.

  801. 40:02

    What should I do?

  802. 40:04

    This is the problem we have. So first

  803. 40:07

    thing what we have to deal do is that

  804. 40:10

    240 GB and 80 uh GB H100.

  805. 40:16

    So and I have to fit only in one GPU or

  806. 40:19

    not in multiple GPU. So what can we do?

  807. 40:22

    I think simple step is that just

  808. 40:25

    compress it. But how should we compress

  809. 40:29

    it? Uh that's the another challenge. So

  810. 40:31

    if we compress BF BF float 16 to FP8 uh

  811. 40:36

    then it will be around 120 GB but our

  812. 40:39

    GPU H100 is still 80 GB. So what I think

  813. 40:43

    they did is that they compressed it into

  814. 40:45

    further MX uh MX FP4 and I think size is

  815. 40:51

    around 65 GB. So this is something we

  816. 40:55

    can do uh compress but question so and

  817. 41:00

    we will use over this ostrich algorithm

  818. 41:03

    we are assuming that uh there is no loss

  819. 41:05

    in compressing a bigger model into a a

  820. 41:09

    smaller size. Second thing

  821. 41:12

    in uh in this one okay yeah so in this

  822. 41:17

    one in this slide we have used this

  823. 41:18

    mistral 7B so 7 billion parameters so

  824. 41:22

    it's a small model 7 billion parameters

  825. 41:24

    so uh so if you multiply it by two bytes

  826. 41:27

    so it so weight of it's around is 14

  827. 41:31

    14.5 GB which can easily fit into H100

  828. 41:35

    or even a a40 so

  829. 41:39

    so Next uh what we can do is that like

  830. 41:43

    mistral 7B instead of compressing it a

  831. 41:46

    floating point 16 we can apply different

  832. 41:49

    techniques like int 8 or int4 or nf4. So

  833. 41:53

    basically we have to just use ostrich

  834. 41:55

    algorithm and just believe that uh there

  835. 41:58

    is no quality loss kind of things but

  836. 42:01

    somehow we also have to mathematically

  837. 42:03

    prove that by doing some kind of test

  838. 42:05

    testing on some external benchmark that

  839. 42:07

    whether it is working or not. So the and

  840. 42:12

    this comes under post training

  841. 42:14

    quantization kind of thing. One can also

  842. 42:16

    do uh this one uh during finetuning one

  843. 42:20

    can also do this kind of quantization.

  844. 42:22

    This comes under a quant training kind

  845. 42:24

    of thing. So uh let's move to our next

  846. 42:28

    problem.

  847. 42:31

    So

  848. 42:34

    we have this huge matrices just just

  849. 42:38

    imagine imagine uh 1,000 by 1,000 uh

  850. 42:43

    dimension matrix A and another matrix

  851. 42:47

    matrix um 1,000 by 1,000. So if we

  852. 42:51

    multiply uh if we multiply by this two

  853. 42:54

    matrices so number of operations will be

  854. 42:57

    1,000 raised to the power q and this is

  855. 43:01

    kind of a problem in terms of uh uh in

  856. 43:05

    terms of computing. So we wondered our

  857. 43:07

    matrix multiplication should be fast and

  858. 43:10

    it should save memory. So what should we

  859. 43:14

    do? We have a giant matrix. Okay, let's

  860. 43:18

    take this one. Uh, Mr. 4096 by 4096.

  861. 43:22

    What should we do uh to

  862. 43:25

    solve our problem of speeding up the

  863. 43:28

    things and saving the memory 4096 by

  864. 43:31

    4096.

  865. 43:33

    So first thing is that we will use just

  866. 43:35

    our world cup algorithm. We can decide a

  867. 43:38

    random number just break the block

  868. 43:41

    vertically. It does not matter what you

  869. 43:43

    are choosing it. So you have so let's

  870. 43:47

    say uh we have 4096 uh columns we will

  871. 43:51

    break it uh we will break it into a

  872. 43:54

    group of 128 column each. So 128, 128, 128

  873. 44:00

    128 uh vertical vert uh vertically so we

  874. 44:04

    will get a 30 we will get this 32 blocks

  875. 44:07

    if we divide this 4096

  876. 44:09

    then

  877. 44:11

    what will happen by doing this thing? So

  878. 44:13

    if we just divide this one vertical

  879. 44:16

    vertically then we can use a multiple

  880. 44:19

    GPU to speed up the process. So this

  881. 44:22

    kind of thing is called multi head

  882. 44:25

    attention.

  883. 44:27

    So what else can we do? We have a big

  884. 44:30

    matrix like

  885. 44:33

    uh as I have mentioned that ostrich

  886. 44:35

    algorithm. So our main problem is

  887. 44:39

    sizing. So what we what we can do is

  888. 44:42

    that instead of having all those 32 uh

  889. 44:45

    32 vertical blocks we will throw away uh

  890. 44:48

    31 blocks and we will assume that one

  891. 44:51

    block is sufficient enough that all the

  892. 44:54

    queries uh can handle those blocks. Our

  893. 44:58

    loss will be almost negligible and we

  894. 45:02

    come up with this algorithm uh which uh

  895. 45:04

    and this algorithm is called a

  896. 45:06

    multiquery attention. So as we can see

  897. 45:10

    right now we are at two spectrum. One is

  898. 45:12

    multi head attention where we split it

  899. 45:16

    into 32 blocks and use different uh

  900. 45:20

    different uh GPUs or do some parallel

  901. 45:22

    processing and at the same time we are

  902. 45:25

    just throwing 31 blocks and uh we are

  903. 45:28

    calling this is as a multi-query

  904. 45:31

    attention. So

  905. 45:34

    uh so at both extreme we should be come

  906. 45:36

    up with a middle ground like something

  907. 45:39

    we can say that

  908. 45:41

    instead of throwing all the 31 uh maybe

  909. 45:44

    we can group we can group we can group

  910. 45:46

    some of the blocks together so that uh

  911. 45:50

    uh and we can assume that uh similar

  912. 45:53

    blocks will attend to a um similar kind

  913. 45:57

    of uh queries. So this kind of technique

  914. 46:00

    comes under grouped query attention

  915. 46:02

    which is very popular right now. Uh even

  916. 46:04

    in uh even in mistral or in other models

  917. 46:08

    this grouped query attention works. So

  918. 46:11

    right now we have understand that we

  919. 46:14

    have a big matrix uh we can divide it

  920. 46:16

    the way we want and doing some

  921. 46:18

    mathematical calculation prove that loss

  922. 46:21

    is almost negligible kind of thing. So

  923. 46:23

    what else we can do?

  924. 46:26

    So after that uh after this grouped

  925. 46:29

    query attention

  926. 46:32

    uh

  927. 46:34

    see

  928. 46:36

    uh we have a big matrix uh one is one is

  929. 46:40

    key and one is value.

  930. 46:42

    Let's compress that matrix into a latent

  931. 46:46

    vector and then come up with some

  932. 46:49

    algorithm to uh reconstruct from latent

  933. 46:52

    vector uh to our original matrix. So

  934. 46:55

    this kind of a strategy comes under this

  935. 46:58

    one um multi head latent latent

  936. 47:01

    attention but again it has some problems

  937. 47:04

    with rope because rope is position

  938. 47:06

    dependent and uh and it is position

  939. 47:08

    independent kind of thing. So yeah one

  940. 47:11

    needs to also include some uh index for

  941. 47:13

    keys also so that one can map it. But

  942. 47:17

    again main problem is that why why we

  943. 47:21

    are why we are multiplying all those big

  944. 47:24

    matrices. So because that's how this

  945. 47:27

    attention mechanism works that

  946. 47:30

    each token will pay attention to every

  947. 47:33

    token. So how about let's don't pay

  948. 47:36

    attention to all the previous token only

  949. 47:38

    pay attention to the important tokens uh

  950. 47:41

    which is important for us. So this is a

  951. 47:44

    kind of uh this kind of field is uh

  952. 47:47

    evolving. So this comes under sparse uh

  953. 47:49

    deepseek sparse attention. So

  954. 47:53

    uh yeah and yeah yeah yeah so okay next

  955. 48:00

    yeah so next one is flash attention. So

  956. 48:04

    uh so in flash attention so main pro so

  957. 48:07

    main problem is that uh

  958. 48:11

    uh so so currently so so currently not

  959. 48:14

    currently so right now almost everyone

  960. 48:16

    uses flash attention but way in 2022 or

  961. 48:19

    2023 uh so that's how it works that's

  962. 48:23

    how it works is that uh so

  963. 48:28

    uh this

  964. 48:29

    Q K query and A and key matrices they

  965. 48:33

    were in HBM. Uh it loads uh it uh first

  966. 48:38

    uh it loads into uh this one uh tensor

  967. 48:41

    core and it do some uh it do some

  968. 48:44

    calculation and then it will uh write it

  969. 48:46

    back to uh HBM and then uh this process

  970. 48:49

    goes on multiple times. So in flash

  971. 48:52

    attention uh what they did is that

  972. 48:56

    uh is that instead of multiplying the

  973. 48:58

    whole matrices so they just divided it

  974. 49:01

    into like our world cup algorithm

  975. 49:03

    divided the bigger matrices into a small

  976. 49:06

    tile and only put those small tiles uh

  977. 49:08

    into a SBM so that uh it can process

  978. 49:12

    multiplication fast and just uh keep uh

  979. 49:16

    keeping track of this some three

  980. 49:17

    variables so that they can calculate

  981. 49:19

    this online softmax.

  982. 49:23

    Yeah.

  983. 49:25

    Next one. So, yeah. So, so this is just

  984. 49:28

    mathematics. So, if we have a multi head

  985. 49:31

    attention if it is 524

  986. 49:34

    uh KV uh then it depends upon how much

  987. 49:38

    how much grouping we want and so if

  988. 49:42

    instead of 32 KV head we only want to

  989. 49:46

    use uh 8 KV heads. So uh so so we can

  990. 49:50

    get a compression of 4x times and this

  991. 49:53

    multi head latent attention this formula

  992. 49:56

    depends on the model to model how many

  993. 49:59

    layers your model have. So in the

  994. 50:01

    original deepseek paper uh I think they

  995. 50:03

    have some 128 dimension

  996. 50:07

    128 d 12 I don't remember the exact

  997. 50:10

    dimension but according to that uh they

  998. 50:13

    have used uh this one latent vector in

  999. 50:16

    which they have used 512 as a dimension

  1000. 50:19

    and some 64

  1001. 50:21

    for for rope index. So and then they

  1002. 50:25

    show that it is a 50x 56x

  1003. 50:29

    uh more compressed than multi head

  1004. 50:32

    attention.

  1005. 50:37

    Okay.

  1006. 50:39

    Yeah. So uh so yeah so this is uh so

  1007. 50:42

    this is the uh this is the trade-off uh

  1008. 50:45

    trade-off diagram. So here I think we

  1009. 50:46

    have not talked about this linear

  1010. 50:48

    attention or mamba. So main problem is

  1011. 50:52

    just all this m Matrix multiplication.

  1012. 50:55

    Right now everyone is using attention.

  1013. 50:57

    Suppose in future

  1014. 51:00

    uh if we don't want to use attention or

  1015. 51:03

    rather than generating tokens

  1016. 51:05

    sequentially just use maybe diffusion

  1017. 51:07

    models where we can generate everything

  1018. 51:09

    simultaneously. So all these algorithms

  1019. 51:12

    will change also. But here I think they

  1020. 51:15

    have two more. One is linear attention

  1021. 51:17

    and one is mamba. So according to uh

  1022. 51:20

    this slide so

  1023. 51:23

    if we are not compressing anything so

  1024. 51:25

    MHA is just we are parallelizing the

  1025. 51:28

    process so there is no quality loss so

  1026. 51:31

    it's a good and then this uh grouped

  1027. 51:34

    query attention which is I think almost

  1028. 51:36

    uh every model is using uh just GQA and

  1029. 51:40

    DSA kind of thing or yeah

  1030. 51:45

    I think same thing we are providing in

  1031. 51:46

    the attention mechanism scorecard So uh

  1032. 51:50

    so I think uh this one mha quality is

  1033. 51:53

    good throughput is uh throughput is okay

  1034. 51:56

    and for grouped query attention it

  1035. 51:59

    depends upon your use case also though

  1036. 52:02

    yeah though

  1037. 52:04

    quality is almost similar to uh multi

  1038. 52:07

    head attention but use case also matters

  1039. 52:09

    a lot yeah multi-query attention is just

  1040. 52:12

    one extreme we are

  1041. 52:15

    I don't know why but we are just

  1042. 52:17

    assuming that we only need one block and

  1043. 52:20

    all the queries will attend to that

  1044. 52:22

    smaller smaller block. So, so quality is

  1045. 52:26

    not that great for M for MQA and this

  1046. 52:30

    multi head latent attention. So yeah if

  1047. 52:34

    you have tried some this deep seat

  1048. 52:36

    models so I think uh they are doing

  1049. 52:38

    great job yeah in in quality wise

  1050. 52:42

    besides that sliding window so all these

  1051. 52:45

    are sub techniques which

  1052. 52:48

    yeah yeah all these are some techniques

  1053. 52:50

    like I just slide the windows all those

  1054. 52:53

    things and instead of yeah instead of

  1055. 52:56

    multiplying everything so linear

  1056. 52:59

    attention is just saying that sum

  1057. 53:00

    summarize everything first uh and then

  1058. 53:03

    look up into it and then mamba this is

  1059. 53:06

    just a state space model. Yeah,

  1060. 53:12

    I can cover that. Okay.

  1061. 53:15

    Uh cool. Uh thank you T.

  1062. 53:18

    So for the model like optimizations we

  1063. 53:22

    also have like the two notebooks

  1064. 53:25

    here.

  1065. 53:28

    So there will be

  1066. 53:32

    I have to go to this.

  1067. 53:42

    Okay. Uh so for the quantization uh like

  1068. 53:47

    the demo

  1069. 53:49

    uh this is is this already run? No. Let

  1070. 53:53

    me just run this.

  1071. 54:03

    Okay. So we are loading the model which

  1072. 54:05

    is like uh ML 7B.

  1073. 54:12

    Uh so

  1074. 54:17

    this one is like with the FP16 baseline.

  1075. 54:29

    Wait.

  1076. 54:31

    Uh, did it run?

  1077. 54:35

    Okay. So, it's uh two millisecond run.

  1078. 54:40

    Did this run? Okay. So, yeah, this time

  1079. 54:43

    it's fetching that model with the FP16

  1080. 54:47

    precision.

  1081. 54:57

    the Wi-Fi.

  1082. 55:03

    It's going to take time.

  1083. 55:07

    Okay.

  1084. 55:11

    >> Yeah, it because it's downloading the

  1085. 55:13

    weights from the hugging face.

  1086. 55:17

    >> Huh.

  1087. 55:20

    Yeah. So, MOLAB is like running online.

  1088. 55:23

    >> Yes.

  1089. 55:26

    because it needs to make the network

  1090. 55:27

    call through to the hugging phase and

  1091. 55:29

    like it fetching

  1092. 55:32

    I don't know like but it's taking time

  1093. 55:34

    to download probably

  1094. 55:52

    Okay.

  1095. 55:55

    So good. Okay. So here we see like the

  1096. 55:59

    memory size is like 15 GB around

  1097. 56:02

    approximately with the FP16 precision.

  1098. 56:05

    We are trying to do the 2x compression

  1099. 56:08

    as Tmet talked about with the int8.

  1100. 56:13

    Let's download. Okay. So we do see like

  1101. 56:16

    your memory size is now like 7.5 GB.

  1102. 56:21

    What that means is now you have a more s

  1103. 56:23

    more memory for your KV to basically

  1104. 56:26

    grow. That means you can either serve

  1105. 56:28

    higher context limit or you can serve

  1106. 56:30

    the higher concurrent users there.

  1107. 56:36

    If you do the like in your basic you are

  1108. 56:39

    doing the 4x compression so that with

  1109. 56:42

    the 4x compression it would be more

  1110. 56:45

    lower. It would be I think around

  1111. 56:48

    3 to 4 GB.

  1112. 56:51

    Yeah. 4.5 GB

  1113. 56:55

    and Yep. So this is Wait.

  1114. 57:02

    So this is just a basic plot

  1115. 57:05

    of like

  1116. 57:07

    so these are the like theoretical

  1117. 57:09

    numbers. uh we are not doing the like

  1118. 57:11

    any throughput test here but uh usually

  1119. 57:13

    you would see like your memory increases

  1120. 57:15

    so pro you would also have like a bit of

  1121. 57:18

    higher uh throughput.

  1122. 57:21

    Uh from some of the benchmarks that we

  1123. 57:23

    studied we saw like the intate uh

  1124. 57:26

    compression it does have like a lower

  1125. 57:28

    throughput.

  1126. 57:32

    Okay. And then there is like a demo on

  1127. 57:36

    the like the attention mechanisms.

  1128. 57:42

    So for the attention okay I have to run

  1129. 57:47

    this.

  1130. 57:58

    Uh okay so it has run. Oh, wait. Why

  1131. 58:04

    does it say no GPU detected?

  1132. 58:09

    It should say the GPU should be

  1133. 58:11

    detected.

  1134. 58:18

    Oh, okay.

  1135. 58:37

    Wait,

  1136. 58:50

    but this is surprising.

  1137. 58:57

    Yeah, I guess it's not like able to

  1138. 58:59

    detect the GPU for some reason.

  1139. 59:04

    Uh we do have like a GPU here.

  1140. 59:11

    Uh okay, never mind.

  1141. 59:14

    Yeah. Yeah. So, but the like basic idea

  1142. 59:16

    here was more like

  1143. 59:20

    as you try to move towards like

  1144. 59:22

    compressing the computation like by

  1145. 59:25

    using different attention mechanisms

  1146. 59:27

    like moving from the multi head to the

  1147. 59:30

    grouped query attention and then to the

  1148. 59:33

    MLA you would start seeing some

  1149. 59:35

    optimizations.

  1150. 59:38

    Um I think yesterday night we were doing

  1151. 59:41

    some benchmarking. Uh I wanted to

  1152. 59:44

    correct this part. Uh so it wasn't like

  1153. 59:47

    50 56x it was 14x. Uh basically the demo

  1154. 59:52

    had a mistake of like a computation uh

  1155. 59:55

    where it did not multiply the number of

  1156. 59:58

    layers.

  1157. 1:00:01

    Uh yeah so apologies for that. Uh so

  1158. 1:00:04

    this MLA is like a 14x savings work in

  1159. 1:00:08

    comparison to like your multi head

  1160. 1:00:10

    attention.

  1161. 1:00:14

    Uh so now that we have understanding of

  1162. 1:00:18

    the pain points, the foundations, the

  1163. 1:00:21

    one side of the optimizations which is

  1164. 1:00:23

    the model optimizations,

  1165. 1:00:25

    we want to talk about what can you do on

  1166. 1:00:29

    the like the serving side.

  1167. 1:00:33

    So

  1168. 1:00:36

    the first thing is we saw like when you

  1169. 1:00:38

    perform like a simple decode step you

  1170. 1:00:42

    are pulling it you are basically pulling

  1171. 1:00:44

    the model weights and then you are

  1172. 1:00:45

    recomputing the key and the value

  1173. 1:00:47

    vectors for all the previous tokens even

  1174. 1:00:51

    though you already computed the those

  1175. 1:00:53

    vectors for the tokens.

  1176. 1:00:56

    So there is definitely like a lot of

  1177. 1:00:59

    compute wastage.

  1178. 1:01:01

    Uh and if you kind of analyze the time

  1179. 1:01:04

    complexity of it, it would come out to

  1180. 1:01:06

    be O of N². Uh and the way to resolve

  1181. 1:01:10

    that is like a classic trade-off against

  1182. 1:01:11

    the memory. You can maintain a memory of

  1183. 1:01:15

    those vectors against the tokens and you

  1184. 1:01:18

    can reference that memory. So that

  1185. 1:01:20

    memory was called as like KV cache.

  1186. 1:01:24

    uh and the like the flow looks something

  1187. 1:01:26

    like this

  1188. 1:01:30

    and then based on this KV cache there

  1189. 1:01:32

    were like four optimizations that were

  1190. 1:01:34

    really possible.

  1191. 1:01:36

    Um

  1192. 1:01:38

    the first one is about the page

  1193. 1:01:41

    detention. So what's the different

  1194. 1:01:44

    what's the problem today? So when you

  1195. 1:01:46

    send like multiple requests as the input

  1196. 1:01:48

    to the GPU

  1197. 1:01:50

    these requests are in a batch

  1198. 1:01:54

    uh every request is allocated like a

  1199. 1:01:57

    continuous memory storage let's say of

  1200. 1:02:01

    I'm just taking an example like let's

  1201. 1:02:03

    set uh 2 KB

  1202. 1:02:06

    however like your request needed only

  1203. 1:02:08

    let's say

  1204. 1:02:10

    uh 1 KB so there is like u 50% of that

  1205. 1:02:16

    memory fragmentation.

  1206. 1:02:19

    Uh and this fragmentation basically

  1207. 1:02:22

    leads to the memory wastage. That means

  1208. 1:02:26

    there was a space in the memory where

  1209. 1:02:28

    you could have served more requests but

  1210. 1:02:31

    you could not because you were looking

  1211. 1:02:33

    for that contigious block of the memory.

  1212. 1:02:36

    So an inspiration to was being taken

  1213. 1:02:39

    from like how the OS works like you

  1214. 1:02:42

    maintain a logical memory and you

  1215. 1:02:44

    basically have a physical memory.

  1216. 1:02:47

    So in the logical memory it would still

  1217. 1:02:51

    feel like

  1218. 1:02:53

    uh that the KV vector for the like every

  1219. 1:02:57

    token is like a contiguous

  1220. 1:03:00

    but it will be mapping to a different

  1221. 1:03:02

    physical address.

  1222. 1:03:06

    So that really helped like saving a lot

  1223. 1:03:10

    of memory. Uh and it was only possible

  1224. 1:03:14

    because you they considered like memory

  1225. 1:03:16

    as a set of blocks and you would be

  1226. 1:03:19

    dynamically allocating those blocks as

  1227. 1:03:21

    the request need as the like new tokens

  1228. 1:03:25

    comes in and they need that kind of

  1229. 1:03:27

    memory.

  1230. 1:03:30

    The another lever is like when you are

  1231. 1:03:34

    sending multiple requests

  1232. 1:03:37

    in the batch

  1233. 1:03:39

    GPU is like taking those requests

  1234. 1:03:44

    but it does not accepts the new batch

  1235. 1:03:46

    unless all the requests in that batch

  1236. 1:03:48

    gets completed. So the diagram looks

  1237. 1:03:51

    more like a page retention but here it

  1238. 1:03:53

    is more about like when is GPU available

  1239. 1:03:57

    to take the next batch. So there is a

  1240. 1:04:01

    time period where GPU is like sitting

  1241. 1:04:03

    really idle

  1242. 1:04:05

    and you want to like resolve for that

  1243. 1:04:09

    and for that like the idea was like okay

  1244. 1:04:11

    let's do that continuous batching.

  1245. 1:04:17

    So the continuous batching also really

  1246. 1:04:19

    helped with like throughput because now

  1247. 1:04:21

    you can ship more requests pretty

  1248. 1:04:24

    quickly. Keep making sure like GPU

  1249. 1:04:26

    always uh get is always like occupied

  1250. 1:04:30

    and it's not like uh sitting idle. So

  1251. 1:04:33

    you are saving on that compute.

  1252. 1:04:36

    The third is the like prefix caching. So

  1253. 1:04:39

    you remember like the KV cache helped

  1254. 1:04:41

    you save the computation for a single

  1255. 1:04:44

    request across the tokens.

  1256. 1:04:47

    But what if like you have the same

  1257. 1:04:50

    tokens across multiple requests? How do

  1258. 1:04:53

    you basically save against that? So the

  1259. 1:04:56

    prefix caching uh which was introduced

  1260. 1:04:59

    by VLM

  1261. 1:05:03

    exactly counters that

  1262. 1:05:06

    and then the third is like we talked

  1263. 1:05:09

    about the fourth actually. So we talked

  1264. 1:05:12

    about quantizing the model

  1265. 1:05:15

    but you could also you can also like

  1266. 1:05:18

    quantize the KV weights.

  1267. 1:05:21

    So that means now you you need like a

  1268. 1:05:24

    lesser space for your key and the value

  1269. 1:05:27

    vectors. That means you can serve more

  1270. 1:05:29

    key and the value vectors in the memory.

  1271. 1:05:32

    And that means like you can serve more

  1272. 1:05:34

    tokens. That means you can serve more

  1273. 1:05:36

    context context limit. And that means

  1274. 1:05:38

    like you can serve more model quality

  1275. 1:05:45

    and all of this is like uh already

  1276. 1:05:49

    present in the VLM.

  1277. 1:05:51

    You don't really need to reinvent that

  1278. 1:05:54

    wheel

  1279. 1:05:56

    uh and you can like deploy this VLM in

  1280. 1:05:59

    production and you could see that

  1281. 1:06:02

    basically growth.

  1282. 1:06:05

    So next we have like a benchmark that we

  1283. 1:06:08

    did. So this benchmark was

  1284. 1:06:12

    let me see if I have that

  1285. 1:06:17

    here

  1286. 1:06:19

    the demos.

  1287. 1:06:23

    So doing this benchmark takes like

  1288. 1:06:26

    around 1 hour because you have to

  1289. 1:06:28

    continuously stop and like restart the

  1290. 1:06:30

    VLM servers and you have to load the

  1291. 1:06:33

    models and all. So it does take a lot of

  1292. 1:06:36

    time in doing the testing but I can like

  1293. 1:06:39

    really tell you here what we are doing.

  1294. 1:06:42

    So we have kept the model as same like

  1295. 1:06:45

    the Mistful 7B.

  1296. 1:06:48

    Uh and then we have like the set of

  1297. 1:06:51

    input questions that we are sending. Uh

  1298. 1:06:55

    consider them as the prompts. Then we

  1299. 1:06:57

    have couple of helper functions here

  1300. 1:06:59

    like checking the server is up or not.

  1301. 1:07:02

    The server is the VLM server.

  1302. 1:07:05

    Then there are helper functions to get

  1303. 1:07:08

    the VLM metrics.

  1304. 1:07:10

    uh and I will talk about like what those

  1305. 1:07:12

    metrics are. Uh then there are like lot

  1306. 1:07:15

    of the benchmarks and all and then you

  1307. 1:07:18

    have to measure uh the KV usage and all.

  1308. 1:07:23

    So these are the like helper functions.

  1309. 1:07:25

    So the baseline is very simple like we

  1310. 1:07:27

    have a hugging phase baseline.

  1311. 1:07:30

    Uh this is the raw like sending the text

  1312. 1:07:33

    to the LLM getting back the response. We

  1313. 1:07:37

    see some results here. We saw like

  1314. 1:07:40

    hugging phase has a throughput of like

  1315. 1:07:42

    around 51 tokens per second. Time to

  1316. 1:07:44

    first token was like 54 and then the

  1317. 1:07:46

    inter token latency was 19.

  1318. 1:07:50

    Uh this bas uh this was all run on the

  1319. 1:07:52

    h100.

  1320. 1:07:55

    Uh and then we start like a very default

  1321. 1:07:59

    VLM server. So by default VLM provides

  1322. 1:08:02

    you the page detention, continuous

  1323. 1:08:04

    batching

  1324. 1:08:06

    and the KV caching.

  1325. 1:08:08

    So three things are present by default

  1326. 1:08:12

    and when you try to compare those

  1327. 1:08:15

    benchmarks you see your throughput is

  1328. 1:08:18

    like almost 15x you are able to serve

  1329. 1:08:22

    more tokens per second

  1330. 1:08:25

    then

  1331. 1:08:26

    your time to the first token

  1332. 1:08:30

    uh that also rises

  1333. 1:08:34

    and then your v the inter token latency

  1334. 1:08:37

    kind goes down and then your KV versus

  1335. 1:08:41

    users and the versus context rate

  1336. 1:08:42

    increases for sure.

  1337. 1:08:47

    Now when you apply the prefix caching to

  1338. 1:08:50

    it

  1339. 1:08:52

    so with the prefix caching you see like

  1340. 1:08:54

    your throughput increases

  1341. 1:08:57

    more your TDF decreases your inter token

  1342. 1:09:01

    latency is approximately same uh and

  1343. 1:09:04

    then your KV cache usage versus the

  1344. 1:09:07

    users it's kind of going down

  1345. 1:09:10

    the vers context it's not going down

  1346. 1:09:12

    it's approximately same I think this is

  1347. 1:09:15

    also approximately same it's like not

  1348. 1:09:18

    that uh big of a deal

  1349. 1:09:21

    when you apply the like KV quantization

  1350. 1:09:24

    on top of it.

  1351. 1:09:27

    So it becomes like so so you see like

  1352. 1:09:31

    your throughput is like almost similar.

  1353. 1:09:34

    Your time to first token is similar.

  1354. 1:09:36

    Your token latency is similar but then

  1355. 1:09:40

    your KV usage actually goes down. And

  1356. 1:09:42

    this is because like you have quantized

  1357. 1:09:45

    your key value space.

  1358. 1:09:48

    Uh and then there is a concept of

  1359. 1:09:51

    speculative decoding that TME will talk

  1360. 1:09:54

    about. Uh

  1361. 1:09:56

    so when you try to benchmark those so

  1362. 1:10:00

    you also see like there is a uh like a

  1363. 1:10:03

    bit of like the less KV usage there

  1364. 1:10:06

    although like the results are

  1365. 1:10:07

    approximately same.

  1366. 1:10:15

    So yeah, I mean overall like these are

  1367. 1:10:19

    the like the metrics across probably I

  1368. 1:10:22

    should

  1369. 1:10:25

    zoom out. Okay, it's not zoom out. It's

  1370. 1:10:27

    not working.

  1371. 1:10:30

    Great. So yeah, this is the like VLM

  1372. 1:10:34

    benchmarks. Um it's your production

  1373. 1:10:36

    default by the way. uh we will also

  1374. 1:10:39

    share that decision tree uh when we try

  1375. 1:10:43

    to talk about like the other engines.

  1376. 1:10:49

    So

  1377. 1:10:51

    yeah, so we should talk about like what

  1378. 1:10:54

    are some of the other inference

  1379. 1:10:56

    optimizations we can do on top of it and

  1380. 1:10:59

    what were some of the other solutions

  1381. 1:11:01

    that came out.

  1382. 1:11:05

    Uh so I would like to again invite

  1383. 1:11:07

    Tanme. He's going to talk about like

  1384. 1:11:10

    some of these optimizations.

  1385. 1:11:18

    Oh, sorry. Uh I'm so sorry. Uh I didn't

  1386. 1:11:21

    enable the slides.

  1387. 1:11:25

    Uh what was the Okay, great.

  1388. 1:11:30

    Perfect.

  1389. 1:11:30

    >> Which one?

  1390. 1:11:31

    >> The speculative.

  1391. 1:11:32

    >> Yeah. Thank you, Hersel. Yeah.

  1392. 1:11:36

    So,

  1393. 1:11:37

    so all these are like speculative

  1394. 1:11:39

    decoding all these are the uh so so what

  1395. 1:11:43

    we say uh different flavors of same kind

  1396. 1:11:46

    of soda. So this uh this technique comes

  1397. 1:11:50

    under decoding accelerator. So first one

  1398. 1:11:53

    so we are only talking about this

  1399. 1:11:55

    speculative decoding but there are other

  1400. 1:11:58

    variants like self speculative eagle

  1401. 1:12:01

    medusa

  1402. 1:12:02

    I only like I think uh this one eagle

  1403. 1:12:05

    algorithm

  1404. 1:12:07

    personally I don't think

  1405. 1:12:10

    speculative decoding works because main

  1406. 1:12:12

    problem is alignment okay so let's start

  1407. 1:12:15

    with what is uh speculative decoding

  1408. 1:12:18

    main problem is that in transformer

  1409. 1:12:20

    architecture All these tokens are

  1410. 1:12:22

    generated sequentially one by one by

  1411. 1:12:26

    one. How about just use a smaller model

  1412. 1:12:30

    and let a smaller model to generate

  1413. 1:12:34

    maybe let's say four or five tokens and

  1414. 1:12:38

    this teacher model or we can say

  1415. 1:12:40

    according to our world cup algorithm we

  1416. 1:12:42

    can say referee. So referee will decide

  1417. 1:12:45

    how many uh tokens it accept and this

  1418. 1:12:49

    loop keeps on going on and our

  1419. 1:12:53

    assumption is that there are certain

  1420. 1:12:56

    domain where this kind of things will

  1421. 1:12:59

    work like maybe in decode maybe in

  1422. 1:13:01

    coding or where almost there is no

  1423. 1:13:04

    creativity uh each uh code or syntax is

  1424. 1:13:08

    almost similar. So maybe it can help it.

  1425. 1:13:11

    But uh based on personal testing, I

  1426. 1:13:14

    didn't find this speculative decoding

  1427. 1:13:17

    useful at all. But other techniques like

  1428. 1:13:21

    uh self speculative decoding where

  1429. 1:13:24

    teacher model also have one head

  1430. 1:13:27

    auxiliary head and it will do same

  1431. 1:13:29

    similar kind of things what this base

  1432. 1:13:32

    model or small model is doing it. But

  1433. 1:13:36

    then this eagle came Eagle 1 2 3 I don't

  1434. 1:13:39

    know how many version versions are but

  1435. 1:13:42

    it is just saying that instead of

  1436. 1:13:45

    creating instead of generating tokens uh

  1437. 1:13:47

    let's uh train a small model inside

  1438. 1:13:50

    train a small model and just take a

  1439. 1:13:53

    features from one of its uh one of main

  1440. 1:13:57

    models layer so that instead of

  1441. 1:13:59

    generating token uh it will generate uh

  1442. 1:14:01

    this features so so uh so eagle is uh

  1443. 1:14:05

    Eagle is better compared to this other

  1444. 1:14:09

    kind of technologies and then another

  1445. 1:14:11

    one is Medusa which is just saying that

  1446. 1:14:14

    just generate all the tokens parallelly.

  1447. 1:14:18

    Uh okay. So here so here in this slide

  1448. 1:14:23

    >> yeah the next slide.

  1449. 1:14:25

    >> Okay.

  1450. 1:14:29

    Okay. Yeah. Okay. Now we come to uh now

  1451. 1:14:33

    we will come to this one prefix caching.

  1452. 1:14:35

    So I don't know whether people are using

  1453. 1:14:37

    this one static prefix caching or not

  1454. 1:14:39

    but thing is that main problem with

  1455. 1:14:42

    prefix caching is that sometimes we type

  1456. 1:14:46

    and make a small kind of mistake and

  1457. 1:14:48

    this standard static prefix caching is

  1458. 1:14:51

    basically it takes a prompt do some

  1459. 1:14:53

    hashing and then next time when user

  1460. 1:14:55

    asks similar kind of question it will

  1461. 1:14:57

    try to match the hash. So if hash is uh

  1462. 1:15:01

    if hash is equal then then it will

  1463. 1:15:04

    instead of recomputing all those K and B

  1464. 1:15:06

    it will just uh take it from from the

  1465. 1:15:09

    storage but you know that sometimes we

  1466. 1:15:11

    make a mistake or maybe we can just

  1467. 1:15:13

    change a word or letter something like

  1468. 1:15:15

    that then we have a very higher uh cache

  1469. 1:15:19

    uh hit cache miss hit rate so that's why

  1470. 1:15:23

    uh this one uh radics tree so radics

  1471. 1:15:26

    tree is becoming very popular and also

  1472. 1:15:29

    also because of agent. So I think almost

  1473. 1:15:32

    everyone is doing agent and most of the

  1474. 1:15:34

    computation is going during TT during

  1475. 1:15:37

    test time inference kind of thing where

  1476. 1:15:39

    we keep on asking same kind of questions

  1477. 1:15:42

    and prompt for example you are an expert

  1478. 1:15:45

    software engineer multiply by 200 times.

  1479. 1:15:49

    This kind of loop keeps on going inside

  1480. 1:15:52

    this uh agentic agentic kind of things

  1481. 1:15:55

    where it is al necessary to keep uh or

  1482. 1:15:59

    store similar kind of things in a radics

  1483. 1:16:03

    tree. So radics tree is just so so radic

  1484. 1:16:07

    tree is just advanced version of this

  1485. 1:16:09

    prefix tree where where we will just

  1486. 1:16:12

    where we will just collapse a node if it

  1487. 1:16:14

    does not have a does not have any branch

  1488. 1:16:18

    and for this kind of work where keep on

  1489. 1:16:23

    repeating same thing this uh red x tree

  1490. 1:16:28

    helps a lot and st lang uh use this kind

  1491. 1:16:32

    of algorithm

  1492. 1:16:33

    for prefix caching.

  1493. 1:16:37

    Okay. Yeah. Then there is another thing.

  1494. 1:16:39

    One is tensor RT LLM. This is very

  1495. 1:16:42

    confusing. When I first started, I was I

  1496. 1:16:46

    was just confused. What is tensor RTLM?

  1497. 1:16:49

    So yeah. So tensor RT is just a uh it's

  1498. 1:16:53

    just a standard uh SDK kind of thing.

  1499. 1:16:56

    Tensor RTLM is just an inference engine

  1500. 1:16:59

    just like VLM, SG lang. But problem is

  1501. 1:17:03

    that it is related to Nvidia. They

  1502. 1:17:07

    optimized each and every layer and every

  1503. 1:17:10

    problem as I mentioned in our world cup

  1504. 1:17:13

    algorithm. They just break everything

  1505. 1:17:15

    and optimized everything at hardware

  1506. 1:17:18

    level also. So uh yeah. So okay next.

  1507. 1:17:27

    Yeah. So for this workshop we also uh

  1508. 1:17:30

    did some benchmarking like which is best

  1509. 1:17:34

    uh so our setup was something similar

  1510. 1:17:37

    was so so we did two kind of testing.

  1511. 1:17:39

    First one is without uh without agentic

  1512. 1:17:43

    testing where we just so

  1513. 1:17:46

    we use this shared GPT uh this one data

  1514. 1:17:48

    set and uh just ask those questions uh

  1515. 1:17:53

    using VLM and SG lang.

  1516. 1:17:57

    Okay.

  1517. 1:18:06

    Yeah. Okay.

  1518. 1:18:09

    And let me just zoom it up. Okay, great.

  1519. 1:18:14

    Okay. Yeah. So, yeah, for this workshop,

  1520. 1:18:16

    we used H100 and of our first testing

  1521. 1:18:20

    was that uh we just uh we just asked uh

  1522. 1:18:24

    we take questions from shared GPT and

  1523. 1:18:26

    put it into VLM, SG lang and we found

  1524. 1:18:30

    that actually there's no statistical

  1525. 1:18:32

    difference between which one is better.

  1526. 1:18:35

    So both have almost similar kind. So

  1527. 1:18:38

    both are fulfilling similar kind of

  1528. 1:18:40

    request per second uh TTFT and latency.

  1529. 1:18:44

    So but only difference we have seen

  1530. 1:18:47

    during agentic uh agentic branching. So

  1531. 1:18:52

    uh what we did was that we asked that

  1532. 1:18:54

    similar kind of question that you are

  1533. 1:18:56

    the best this one software engineer in

  1534. 1:18:58

    the world just solve the problem of

  1535. 1:19:02

    traffic congestion in this city kind of

  1536. 1:19:04

    thing. Then we put this into LLM. LLM

  1537. 1:19:09

    generates some output. Then we did

  1538. 1:19:11

    another uh round two also. So once this

  1539. 1:19:15

    LLM generates this output, then in round

  1540. 1:19:19

    two we have specially mentioned that uh

  1541. 1:19:23

    provide uh review the proposal and give

  1542. 1:19:26

    ratings from 1 to 10. So this uh two

  1543. 1:19:30

    turns we did uh and this loop keeps on

  1544. 1:19:34

    uh repeating it. Uh what we found is

  1545. 1:19:36

    that for this kind of

  1546. 1:19:40

    uh workflow where everything is standard

  1547. 1:19:43

    all those prompts and context

  1548. 1:19:45

    engineering comes into the picture. If

  1549. 1:19:47

    we do proper this agentic branching then

  1550. 1:19:50

    I think uh this HG lang is three to four

  1551. 1:19:53

    times better. But again this depends

  1552. 1:19:56

    upon the different setup maybe uh if you

  1553. 1:19:59

    do it uh you may get different results.

  1554. 1:20:03

    Okay. Yeah. So I think uh did we

  1555. 1:20:07

    uploaded it on GitHub? Okay.

  1556. 1:20:10

    >> Yeah. So the PDF is like also in the

  1557. 1:20:14

    drive. Uh it's the same link as the

  1558. 1:20:17

    slides.

  1559. 1:20:19

    So a quick summary here.

  1560. 1:20:23

    So on a standard API workload throughput

  1561. 1:20:26

    you would see like a VLM and the SG lang

  1562. 1:20:30

    would behave same. So if you don't have

  1563. 1:20:33

    if you have like a standard workload

  1564. 1:20:35

    definitely go with VLM. It's the

  1565. 1:20:37

    production default anyways. But what

  1566. 1:20:39

    Tanme was also saying is when you try to

  1567. 1:20:43

    like make it like agentic workloads that

  1568. 1:20:46

    is where like your SG link really shines

  1569. 1:20:51

    uh and uh it kind of like provides you

  1570. 1:20:53

    all the benefits.

  1571. 1:20:57

    So yeah keep like VLM as a default but

  1572. 1:21:00

    if you have agentic workloads probably

  1573. 1:21:03

    try to move as the towards the SG lang.

  1574. 1:21:05

    if you're not happy with DB LLM. Uh but

  1575. 1:21:12

    uh okay. Uh let me

  1576. 1:21:21

    Okay.

  1577. 1:21:26

    And then like there is like the like a

  1578. 1:21:29

    comparison that is done at the 120

  1579. 1:21:32

    billion like for the GPTO OSS 120

  1580. 1:21:35

    billion. Um this is a benchmark that was

  1581. 1:21:39

    prepared by clarify. So there is like a

  1582. 1:21:44

    blog link here. Oh nice.

  1583. 1:21:48

    Okay. Yeah. So they did the similar

  1584. 1:21:52

    benchmark and they included like a

  1585. 1:21:54

    tensor RT LLM in it.

  1586. 1:21:58

    Definitely you can always go through

  1587. 1:22:00

    these benchmarks and try to understand

  1588. 1:22:02

    which basically suits your use case. As

  1589. 1:22:06

    we mentioned like Tensor RT they try to

  1590. 1:22:08

    optimize the hardware side as well

  1591. 1:22:10

    having the peak hardware performance.

  1592. 1:22:17

    Wait uh this is

  1593. 1:22:22

    okay.

  1594. 1:22:26

    Yeah.

  1595. 1:22:27

    And then like in terms of when you want

  1596. 1:22:30

    to dep pick like your engines

  1597. 1:22:34

    once you figure out like between VLM, SG

  1598. 1:22:37

    lang tenserati so that there are some

  1599. 1:22:39

    new engines that are popping up Nvidia

  1600. 1:22:42

    Dynamo for sure. Uh so they are also for

  1601. 1:22:46

    the agentic uh session routing.

  1602. 1:22:49

    Uh hugging phase is always there. It's a

  1603. 1:22:52

    simple no server. Then there is like an

  1604. 1:22:55

    MSAR

  1605. 1:22:57

    engine that was recently proposed by

  1606. 1:22:59

    Stanford. They are for like the

  1607. 1:23:02

    multimodel.

  1608. 1:23:05

    Uh so definitely you could explore those

  1609. 1:23:08

    and when you try to basically just to

  1610. 1:23:11

    like give a quick summary uh you we

  1611. 1:23:14

    start with like a baseline

  1612. 1:23:17

    we try to find what model could fit our

  1613. 1:23:20

    use cases.

  1614. 1:23:22

    Um,

  1615. 1:23:24

    so you could pick like uh Deep Seek, you

  1616. 1:23:27

    could pick like don't pick like a

  1617. 1:23:30

    Mistral 7B. I mean, it's not good. Uh,

  1618. 1:23:34

    but yeah, so you pick your model and you

  1619. 1:23:38

    want to like have a smaller memory and

  1620. 1:23:41

    you want to try to fit that bigger model

  1621. 1:23:43

    into smaller memory so that you could

  1622. 1:23:45

    save cost on the GPU cost. So you can do

  1623. 1:23:49

    like all those com quantization

  1624. 1:23:52

    then you can apply all those serving

  1625. 1:23:54

    optimizations by using the right serving

  1626. 1:23:56

    engine under the hood. So that can

  1627. 1:23:59

    really provide you that

  1628. 1:24:02

    throughut that you really want.

  1629. 1:24:07

    And

  1630. 1:24:10

    now something that you can do uh after

  1631. 1:24:13

    going back home pro because we cannot

  1632. 1:24:16

    like actually go over all the material

  1633. 1:24:18

    here uh is definitely reading about some

  1634. 1:24:22

    of the source informations like

  1635. 1:24:24

    different attention mechanisms different

  1636. 1:24:26

    like these engines like try to just read

  1637. 1:24:29

    the different benchmarks which are

  1638. 1:24:31

    present online as well

  1639. 1:24:34

    and then there are a lot of like

  1640. 1:24:37

    in-depth guides or the next phases of it

  1641. 1:24:40

    which is like learning about some KV

  1642. 1:24:43

    eviction strategies. So world is moving

  1643. 1:24:46

    towards having a separate KV cache

  1644. 1:24:48

    engineering domain. So you want to

  1645. 1:24:51

    understand what's going on in there. So

  1646. 1:24:53

    KV cache KV eviction cache compressions

  1647. 1:24:56

    hybrid memories. So there are like lot

  1648. 1:24:59

    of solutions that are happening around

  1649. 1:25:00

    there. So always try to stick to those

  1650. 1:25:04

    foundations or like the fundamentals or

  1651. 1:25:07

    the first principles and try to see like

  1652. 1:25:10

    which solution basically solves what

  1653. 1:25:12

    problem and whether you actually need

  1654. 1:25:14

    that problem to be solved for your use

  1655. 1:25:17

    case

  1656. 1:25:18

    and then there is like distributed LLM

  1657. 1:25:21

    inference which is like a different

  1658. 1:25:24

    painoint altogether. Uh you would

  1659. 1:25:27

    probably need like a two-hour workshop

  1660. 1:25:29

    there as well.

  1661. 1:25:31

    uh to like go over like all the

  1662. 1:25:34

    internals do all the hands-on.

  1663. 1:25:41

    Yes. And this is something we are trying

  1664. 1:25:43

    to propose for the AI engineer New York

  1665. 1:25:45

    session uh which is to like dive deeper

  1666. 1:25:48

    into the advanced sections of the LLM

  1667. 1:25:50

    inference. So this workshop was more for

  1668. 1:25:53

    the like beginner and the intermediate

  1669. 1:25:55

    level. Um so in this form we do have

  1670. 1:25:58

    like a feedback as well plus also the

  1671. 1:26:01

    interest. Um if uh you think like we

  1672. 1:26:05

    need certain improvements on certain

  1673. 1:26:07

    sections definitely give that feedback

  1674. 1:26:09

    as well and if you want to see this

  1675. 1:26:11

    workshop in like New York uh fair you I

  1676. 1:26:17

    mean definitely feel free to enroll your

  1677. 1:26:19

    interest.

  1678. 1:26:22

    Uhhuh.

  1679. 1:26:24

    How is it possible?

  1680. 1:26:28

    Well,

  1681. 1:26:34

    let me just check.

  1682. 1:26:46

    >> Huh?

  1683. 1:26:48

    >> URL works, right? Not the QR code. Okay.

  1684. 1:26:52

    Probably I forgot to link those two

  1685. 1:26:54

    together.

  1686. 1:27:00

    Z

  1687. 1:27:02

    G A five.

  1688. 1:27:11

    Okay, cool. Yes. So if you can give that

  1689. 1:27:14

    feedback let me just okay

  1690. 1:27:20

    that will be fine um and yeah I think we

  1691. 1:27:24

    would like to wrap this workshop then

  1692. 1:27:28

    I'm sure like lot of you would be having

  1693. 1:27:30

    a lot of questions so we can take all

  1694. 1:27:32

    those like offline uh we can meet uh and

  1695. 1:27:36

    we can uh like talk about those

  1696. 1:27:37

    questions.

  1697. 1:27:39

    >> Yeah sure. Uh thank you everyone. Thanks

  1698. 1:27:42

    for joining. Uh I think it was really

  1699. 1:27:46

    meaningful and all of you like came

  1700. 1:27:49

    here. Uh thanks a lot.

  1701. 1:27:51

    >> Yeah. Thanks.