xiaohongshu
xiaohongshu
llm-inference-batching-scheduler
Guidance for implementing batching schedulers for LLM inference systems with compilation-based accelerators. This skill applies when optimizing request batching to minimize cost while meeting latency thresholds, particularly when dealing with shape compilation costs, padding overhead, and multi-b...
Full skill instructions
This skill provides systematic approaches for designing batching schedulers that optimize LLM inference workloads on compilation-based accelerators (TPUs, custom ASICs). The core challenge involves balancing multiple competing objectives: minimizing compilation cost (fewer shapes), reducing padding waste (tighter batches), and meeting latency thresholds (P95, P99 constraints).
Apply this skill when:
Compilation-based accelerators require pre-compiled shapes. Each unique (prompt_length, generation_length) shape incurs a one-time compilation cost. The total cost typically follows:
total_cost = per_token_cost × total_tokens + compilation_cost × num_shapes²
The quadratic term on num_shapes creates strong pressure to minimize unique shapes while the
per-token cost penalizes excessive padding.
Before implementing, calculate padding budgets mathematically:
max_padded_tokens = actual_tokens / (1 - max_pad_ratio)padding_budget = max_padded_tokens - actual_tokensThis budget constrains the maximum generation bucket size.
Requests are grouped by generation length into buckets. The bucket size directly affects padding:
To derive optimal bucket size:
optimal_bucket_size ≈ padding_budget / num_requests_in_worst_bucket
Parse the cost model completely
Analyze request distribution
Derive parameter bounds from constraints
Document derived constraints
Instead of ad-hoc trial-and-error, implement structured search:
Define the parameter space
Implement reusable evaluation
Search systematically
Critical invariants to validate continuously
max(prompt_lengths) ≤ max(shape_prompt_dims)sum(batch_sizes) == total_requestslen(unique_shapes) ≤ max_shapesBuild validation into the workflow
Symptom: Assertion errors about uncovered prompt lengths after optimizing shape count.
Cause: When reducing shapes for compilation cost, accidentally removing shapes needed for long prompts.
Prevention:
shape_to_remove.prompt_dim < max(all_prompt_lengths)required_shapes() function that returns non-removable shapesSymptom: Cycling through bucket sizes (20, 21, 22...) without clear rationale, losing track of best configurations.
Cause: Not computing optimal parameters from constraints first.
Prevention:
Symptom: Reducing pad_ratio but exceeding cost threshold, or vice versa.
Cause: Metrics are interconnected—fewer shapes increases padding, smaller buckets increase latency.
Prevention:
Symptom: Re-testing configurations or forgetting which parameters achieved which results.
Prevention:
{config_hash: {params: {...}, metrics: {...}}}Symptom: Plan file passes metric thresholds but fails structural validation (duplicate requests, missing requests).
Prevention:
1. Parse generated plan file
2. Extract all request IDs assigned to batches
3. Verify: set(assigned_ids) == set(all_request_ids)
4. Verify: len(assigned_ids) == len(all_request_ids) # no duplicates
5. Verify: all shapes have prompt_dim >= max prompt in that batch
6. Verify: unique_shape_count <= max_allowed_shapes
1. Compute total padded tokens using shape dimensions
2. Compute actual tokens from request data
3. Calculate: pad_ratio = 1 - (actual / padded)
4. Compute cost using exact cost model formula
5. Simulate latency distribution, extract P95/P99
6. Compare all metrics against thresholds
After any parameter change:
START
│
├─ Is pad_ratio too high?
│ └─ YES → Reduce generation bucket size OR add more prompt shapes
│
├─ Is cost too high?
│ └─ YES → Reduce number of unique shapes (but verify coverage!)
│
├─ Is P95/P99 latency too high?
│ └─ YES → Increase generation bucket size (larger batches, fewer total)
│ OR redistribute requests across batches more evenly
│
└─ All metrics passing?
└─ YES → DONE (record configuration as solution)
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience