⚡ Live Interactive Code Sandbox: AI Dev Tool: In every study that
▶️ Run Code
💳 Unlock Source Code ($5)
📝 Editable Code Sandbox
```python # AI Dev Tool: LLM Speed Test CLI # Description: A command-line tool to test the speed of local LLMs before buying hardware. # Requirements: Python 3.8+, torch, transformers import argparse import torch from transformers import AutoModelForCausalLM, AutoTokenizer import time import json def test_llm_speed(model_name: str, device: str = "cpu") -> dict: """ Test the speed of a local LLM. Args: - model_name (str): The name of the LLM model to test. - device (str): The device to run the model on (default: "cpu"). Returns: - dict: A dictionary containing the test results. """ try: # Load the model and tokenizer model = AutoModelForCausalLM.from_pretrained(model_name) tokenizer = AutoTokenizer.from_pretrained(model_name) # Move the model to the specified device device = torch.device(device if torch.cuda.is_available() else "cpu") model.to(device) # Generate a random input input_text = "This is a test input." # Tokenize the input inputs = tokenizer
🖥️ Interactive Execution Terminal Console
⚡ Ready! Click ▶️ Run Code to execute code in browser terminal...