Llm inference
This skill teaches Claude how to effectively build and deploy applications on Modal's serverless platform.From the repository description
npx -y skills add samarth777/modal-skills --skill llm-inferenceAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
3 things to look at
- reads credentialsReads from 1 credential source: `os.environ["HF_TOKEN"]`.
- 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
- runs commandsInstructs the agent to run 4 commands, including `modal run llm_service.py::download_model` and 3 more.
SKILL.md
4.0 KB, ~1.0k tokens by cl100k_base, as published. Nobody here has run it
LLM Inference Service Example
A complete example of deploying an LLM inference service on Modal using vLLM.
import modal
# --- Configuration ---
MODEL_NAME = "meta-llama/Llama-3.1-8B-Instruct"
GPU_TYPE = "A100"
# --- Image Definition ---
image = (
modal.Image.debian_slim(python_version="3.12")
.pip_install(
"vllm==0.6.0",
"torch==2.4.0",
"transformers",
"huggingface_hub[hf_transfer]",
)
.env({
"HF_HUB_ENABLE_HF_TRANSFER": "1",
"VLLM_ATTENTION_BACKEND": "FLASH_ATTN",
})
)
app = modal.App("llm-inference", image=image)
# --- Model Cache Volume ---
model_volume = modal.Volume.from_name("llm-model-cache", create_if_missing=True)
MODEL_PATH = "/models"
# --- Download Model (Build Step) ---
@app.function(
volumes={MODEL_PATH: model_volume},
secrets=[modal.Secret.from_name("huggingface-secret")],
timeout=3600,
)
def download_model():
from huggingface_hub import snapshot_download
snapshot_download(
MODEL_NAME,
local_dir=f"{MODEL_PATH}/{MODEL_NAME}",
token=os.environ["HF_TOKEN"],
)
model_volume.commit()
# --- Inference Service ---
@app.cls(
gpu=GPU_TYPE,
volumes={MODEL_PATH: model_volume},
container_idle_timeout=300, # Keep warm for 5 minutes
allow_concurrent_inputs=10,
)
class LLMService:
@modal.enter()
def load_model(self):
from vllm import LLM
self.llm = LLM(
model=f"{MODEL_PATH}/{MODEL_NAME}",
tensor_parallel_size=1,
gpu_memory_utilization=0.9,
)
@modal.method()
def generate(
self,
prompt: str,
max_tokens: int = 256,
temperature: float = 0.7,
) -> str:
from vllm import SamplingParams
params = SamplingParams(
temperature=temperature,
max_tokens=max_tokens,
)
outputs = self.llm.generate([prompt], params)
return outputs[0].outputs[0].text
@modal.method()
def generate_batch(
self,
prompts: list[str],
max_tokens: int = 256,
temperature: float = 0.7,
) -> list[str]:
from vllm import SamplingParams
params = SamplingParams(
temperature=temperature,
max_tokens=max_tokens,
)
outputs = self.llm.generate(prompts, params)
return [o.outputs[0].text for o in outputs]
# --- Web API ---
@app.function()
@modal.fastapi_endpoint(method="POST", docs=True)
def generate(body: dict) -> dict:
service = LLMService()
result = service.generate.remote(
prompt=body["prompt"],
max_tokens=body.get("max_tokens", 256),
temperature=body.get("temperature", 0.7),
)
return {"response": result}
# --- Streaming Endpoint ---
@app.function()
@modal.fastapi_endpoint(method="POST")
async def generate_stream(body: dict):
from fastapi.responses import StreamingResponse
# For streaming, you'd use vLLM's async engine
# This is a simplified example
service = LLMService()
result = service.generate.remote(
prompt=body["prompt"],
max_tokens=body.get("max_tokens", 256),
)
async def stream():
# In production, use vLLM's streaming
for token in result.split():
yield f"data: {token}\n\n"
return StreamingResponse(stream(), media_type="text/event-stream")
# --- CLI ---
@app.local_entrypoint()
def main(prompt: str = "Explain quantum computing in simple terms."):
print(f"Prompt: {prompt}\n")
service = LLMService()
response = service.generate.remote(prompt)
print(f"Response:\n{response}")
Usage
# Download model first
modal run llm_service.py::download_model
# Test locally
modal run llm_service.py --prompt "What is the meaning of life?"
# Deploy
modal deploy llm_service.py
# Call API
curl -X POST https://your-workspace--llm-inference-generate.modal.run \
-H "Content-Type: application/json" \
-d '{"prompt": "Hello, how are you?", "max_tokens": 100}'
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.
Gives 0 of the 12 instructions most context ai engineering skills give in ~1.0k tokens
Counted across 1,328 of the 2,349 authors here whose files we hold, read 2026-09-06
- Dispatch a fresh subagent for each taskin 76 of 1328, across 59 files
- Perform spec compliance review before code quality reviewin 44 of 1328, across 34 files
- Dispatch a final code reviewer after all tasksin 38 of 1328, across 26 files
- Answer subagent questions before allowing implementationin 36 of 1328, across 26 files
- Use the least powerful model capable of the taskin 33 of 1328, across 26 files
- Create a TodoWrite list for all tasksin 32 of 1328, across 22 files
- Perform a task review after each implementationin 31 of 1328, across 24 files
- Extract all tasks and context from the planin 29 of 1328, across 20 files
- Provide full task text to subagentsin 28 of 1328, across 20 files
- Use git worktrees for isolated workspacesin 25 of 1328, across 20 files
- Specify the model explicitly when dispatching a subagentin 23 of 1328, across 18 files
- Execute all tasks from the plan without stoppingin 21 of 1328, across 16 files
Said here and by no other author read
- Define Modal image with vLLM and torch
- Create model cache volume for storage
- Implement model download function
- Define inference class with GPU requirements
- Expose FastAPI endpoints for generation
- Implement local entrypoint for testing
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.