⚡ Live Interactive Code Sandbox: AI Dev Tool: Show HN Llmspeed
▶️ Run Code
💳 Unlock Source Code ($5)
📝 Editable Code Sandbox
```python # AI Dev Tool: LLM Speed CLI Automation Tool # ============================================ # This tool allows users to test the speed of a local Large Language Model (LLM) # before purchasing hardware. It utilizes the Hono Cloudflare Workers D1 Starter # and AGENTS.md AI-Native SaaS Template for efficient performance. import argparse import time import torch from transformers import AutoModelForCausalLM, AutoTokenizer def test_llm_speed(model_name: str, num_iterations: int) -> float: """ Test the speed of a local LLM by running a series of iterations. Args: - model_name (str): The name of the LLM model to test. - num_iterations (int): The number of iterations to run. Returns: - float: The average time taken per iteration. """ # Load the LLM model and tokenizer model = AutoModelForCausalLM.from_pretrained(model_name) tokenizer = AutoTokenizer.from_pretrained(model_name) # Initialize the total time taken total_time = 0.0 # Run the iterations for _ in range(num_iterations): # Generate a random input prompt prompt = "
🖥️ Interactive Execution Terminal Console
⚡ Ready! Click ▶️ Run Code to execute code in browser terminal...