### Quickstart Guide and Benchmarking Tutorial Updates Source: https://docs.modular.com/max/changelog Information on the updated quickstart guide and benchmarking tutorial, emphasizing ease of use with the MAX CLI. ```APIDOC ## Quickstart Guide and Benchmarking Tutorial Updates ### Description Details on the updated documentation, including a new quickstart guide for model deployment and an updated benchmarking tutorial using the `max benchmark` command. ### Method N/A (Documentation Updates) ### Endpoint N/A (Documentation Updates) ### Parameters N/A ### Request Example N/A ### Response N/A #### New Quickstart Guide - **Description**: A new quickstart guide allows users to select a model architecture and size, then deploy it and run the open-source benchmarking script directly from the `max` CLI. #### Updated Benchmarking Tutorial - **Description**: The benchmarking tutorial has been updated and simplified to utilize the new `max benchmark` command. ``` -------------------------------- ### Install Conda and Initialize Project Source: https://docs.modular.com/max/serve/lora-adapters These commands guide through installing Miniconda (if not present), initializing conda for shell interaction, and creating a new conda environment named 'lora-adapter'. ```bash brew install miniconda ``` ```bash conda init ``` ```bash conda init zsh ``` ```bash conda create -n lora-adapter ``` -------------------------------- ### Verify Mojo Version with Pixi Source: https://docs.modular.com/mojo/manual/gpu/intro-tutorial Runs the Mojo compiler within the Pixi environment to check the installed version, confirming the setup and installation. ```bash pixi run mojo --version ``` -------------------------------- ### Install OpenAI Package with Package Managers Source: https://docs.modular.com/max/get-started Installs the 'openai' Python package using different package managers. Choose the command corresponding to your project's setup (pixi, uv, pip, or conda). ```bash pixi add openai ``` ```bash uv add openai ``` ```bash pip install openai ``` ```bash conda install -c conda-forge openai ``` -------------------------------- ### Initialize a project with uv Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Initializes a new project named 'example-project' using uv. This command sets up the necessary configuration for uv to manage the project. ```bash uv init example-project && cd example-project ``` -------------------------------- ### Create conda project environment Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Creates a new conda environment named 'example-project'. This environment will be used to install project-specific packages. ```bash conda create -n example-project ``` -------------------------------- ### Shell: Install pip and Initialize Project Source: https://docs.modular.com/max/serve/function-calling This example outlines the process of setting up a Python project using pip. It includes creating a project directory, setting up and activating a virtual environment, and installing the 'modular' Python package from either the nightly or stable distribution channels. ```shell mkdir function-calling && cd function-calling python3 -m venv .venv/function-calling && source .venv/function-calling/bin/activate pip install --pre modular \ --index-url https://dl.modular.com/public/nightly/python/simple/ # Or for stable version: pip install modular \ --extra-index-url https://modular.gateway.scarf.sh/simple/ ``` -------------------------------- ### Install and Check MAX Environment Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Installs the necessary MAX environment and checks the versions of MAX and Python. This step ensures that the development environment is correctly set up before proceeding with graph development. ```bash cd src/quickstart pixi run max --version pixi run python --version ``` -------------------------------- ### Initialize Project with uv Source: https://docs.modular.com/max/packages Initializes a new project directory and creates a virtual environment using uv. It then activates the virtual environment. ```shell uv init example-project && cd example-project uv venv && source .venv/bin/activate ``` -------------------------------- ### Shell: Install conda and Initialize Project Source: https://docs.modular.com/max/serve/function-calling This guide demonstrates setting up a project using conda. It covers installing conda (if necessary), initializing conda for shell interaction, creating a new conda environment named 'function-calling', activating it, and installing the 'modular' conda package from specified channels. ```shell # Install conda if needed (e.g., brew install miniconda) conda init # For Mac use: conda init zsh # Restart your terminal conda create -n function-calling conda activate function-calling conda install -c conda-forge -c https://conda.modular.com/max-nightly/ modular # Or for stable version: conda install -c conda-forge -c https://conda.modular.com/max/ modular ``` -------------------------------- ### Create conda environment Source: https://docs.modular.com/max/get-started Creates a new conda environment named 'quickstart'. This environment will be used to manage project dependencies separately from the base conda installation. ```shell conda create -n quickstart ``` -------------------------------- ### List Project Contents Source: https://docs.modular.com/mojo/manual/get-started Lists all files and directories within the current project directory, including hidden files. This helps in verifying the project structure after initialization. ```shell ls -A ``` -------------------------------- ### Initialize a project with pixi Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Initializes a new project named 'example-project' with specified conda channels. After initialization, it changes the directory to the newly created project. ```bash pixi init example-project \ -c https://conda.modular.com/max-nightly/ -c conda-forge \ && cd example-project ``` -------------------------------- ### Create and activate virtual environment with venv Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Creates a virtual environment named '.venv/example-project' and activates it using the 'source' command. This isolates project dependencies. ```bash python3 -m venv .venv/example-project \ && source .venv/example-project/bin/activate ``` -------------------------------- ### Install uv package manager Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Installs the uv package manager using a curl script. uv is a fast Python package installer and resolver. ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` -------------------------------- ### Initialize project with uv Source: https://docs.modular.com/max/get-started Initializes a new project named 'quickstart' using uv. It then changes the current directory to the newly created project folder. ```shell uv init quickstart && cd quickstart ``` -------------------------------- ### Check pip modular version Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Displays information about the installed 'modular' package, including its version. This is useful for verifying the installation. ```bash pip show modular ``` -------------------------------- ### Create project directory Source: https://docs.modular.com/max/get-started Creates a new directory named 'quickstart' for the project and changes the current directory into it. This is a standard way to set up a new project folder. ```shell mkdir quickstart && cd quickstart ``` -------------------------------- ### Install modular package with conda (Stable) Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Installs the stable version of the 'modular' conda package. It specifies conda-forge and the stable channel for modular. ```bash conda install -c conda-forge -c https://conda.modular.com/max/ modular ``` -------------------------------- ### Install modular package with conda (Nightly) Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Installs the nightly version of the 'modular' conda package. It specifies conda-forge and the nightly channel for modular. ```bash conda install -c conda-forge -c https://conda.modular.com/max-nightly/ modular ``` -------------------------------- ### Configure Benchmark with YAML File Source: https://docs.modular.com/max/get-started This command demonstrates how to use a YAML configuration file for benchmarking. This approach allows for more complex and reusable benchmark configurations. Refer to the GitHub repository for example configuration files. ```bash max benchmark \ --config-file "your_benchmark_config.yaml" ``` -------------------------------- ### Install uv and Initialize Project Source: https://docs.modular.com/max/serve/lora-adapters These commands demonstrate installing the uv package manager and initializing a new project. This is the first step in setting up an environment for LoRA adapters using uv. ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` ```bash uv init lora-adapter && cd lora-adapter ``` -------------------------------- ### Install conda package manager Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Installs the conda package manager using Homebrew on a Mac. This is a common way to set up conda on macOS. ```bash brew install miniconda ``` -------------------------------- ### Install modular package with pip (Stable) Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Installs the stable version of the 'modular' Python package using pip. It utilizes an extra index URL for accessing the package repository. ```bash pip install modular \ --extra-index-url https://modular.gateway.scarf.sh/simple/ ``` -------------------------------- ### Serve Gemma 3 Model with MAX CLI Source: https://docs.modular.com/max/get-started Starts a local endpoint for the Gemma 3 language model using the 'max' CLI. Requires Hugging Face access token and agreement to the model license. Ensure a compatible GPU with sufficient VRAM is available. ```bash export HF_TOKEN="hf_..." max serve --model google/gemma-3-27b-it ``` -------------------------------- ### Install modular package with uv (Stable) Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Installs the stable version of the 'modular' Python package using uv. It utilizes an extra index URL for accessing the package repository. ```bash uv pip install modular \ --extra-index-url https://modular.gateway.scarf.sh/simple/ ``` -------------------------------- ### Initialize project with pixi Source: https://docs.modular.com/max/get-started Initializes a new project named 'quickstart' using pixi, adding specified conda channels for the max-nightly and conda-forge repositories. It then changes the current directory to the newly created project. ```shell pixi init quickstart \ -c https://conda.modular.com/max-nightly/ -c conda-forge \ && cd quickstart ``` -------------------------------- ### Clone and Run Mojo Examples from GitHub Source: https://docs.modular.com/mojo/manual/install This section details how to clone the Mojo repository from GitHub, navigate to an example directory (like Conway's Game of Life), and use 'pixi' to manage dependencies, build, and run the example. It also mentions alternatives if 'pixi' is not used. ```bash git clone https://github.com/modular/modular.git ``` ```bash cd modular/examples/mojo/life ``` ```bash pixi run lifev1 ``` ```bash mojo lifev1.mojo ``` -------------------------------- ### Check uv modular version Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Displays information about the installed 'modular' package using uv's pip show command. This verifies the package installation within the uv environment. ```bash uv pip show modular ``` -------------------------------- ### Install modular package with uv (Nightly) Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Installs the nightly version of the 'modular' Python package using uv. It specifies a custom index URL for nightly builds and allows pre-release versions. ```bash uv pip install modular \ --index-url https://dl.modular.com/public/nightly/python/simple/ \ --prerelease allow ``` -------------------------------- ### Benchmark Text Model with Random Data Source: https://docs.modular.com/max/get-started This command benchmarks a text model using randomly generated data. It allows customization of dataset size, prompt count, input/output lengths, image size, and coefficient of variation. Results are printed to the terminal by default. ```bash max benchmark \ --dataset-name random \ --num-prompts 500 \ --random-input-len 40 \ --random-output-len 150 \ --random-image-size 512,512 \ --random-coefficient-of-variation 0.1,0.6 ``` -------------------------------- ### Benchmark Multimodal LLM Endpoint with MAX CLI Source: https://docs.modular.com/max/get-started Benchmarks the performance of a local multimodal LLM endpoint using the 'max' CLI. This command is set up for inference with the InternVL3 model, targeting the chat completions endpoint. ```bash max benchmark \ --model OpenGVLab/InternVL3-14B-Instruct \ --backend modular \ --endpoint /v1/chat/completions ``` -------------------------------- ### Run a 'Hello World' Program in Mojo Source: https://docs.modular.com/mojo/manual/install This snippet demonstrates how to create and execute a basic 'Hello, World!' program using the Mojo programming language. It requires the Mojo CLI to be installed and accessible in your terminal. ```mojo def main(): print("Hello, World!") ``` ```bash mojo hello.mojo ``` -------------------------------- ### Install modular package with pip (Nightly) Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Installs the nightly version of the 'modular' Python package using pip. It specifies a custom index URL for nightly builds and uses '--pre' to allow pre-release versions. ```bash pip install --pre modular \ --index-url https://dl.modular.com/public/nightly/python/simple/ ``` -------------------------------- ### Example Command Line Benchmark Configuration Source: https://docs.modular.com/max/cli/benchmark Demonstrates how to specify benchmark configurations directly on the command line using various options. This is an alternative to using a configuration file. ```bash max benchmark \ --model google/gemma-3-27b-it \ --backend modular \ --endpoint /v1/chat/completions \ --host localhost \ --port 8000 \ --num-prompts 50 \ --dataset-name arxiv-summarization \ --arxiv-summarization-input-len 12000 \ --max-output-len 1200 ``` -------------------------------- ### Activate conda project environment Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Activates the conda environment named 'example-project'. This makes the packages installed in this environment available to the current shell session. ```bash conda activate example-project ``` -------------------------------- ### Initialize Uv Project Source: https://docs.modular.com/max/inference/text-to-text This command initializes a new Uv project named 'chat-quickstart'. It creates a new directory and sets up the project structure for managing Python packages and virtual environments using Uv. ```bash uv init chat-quickstart && cd chat-quickstart ``` -------------------------------- ### Create max_ops directory for pip Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Creates a directory named 'max_ops' and changes the current directory into it. This is a common setup step for projects using pip. ```bash mkdir max_ops cd max_ops ``` -------------------------------- ### Create and activate Python virtual environment Source: https://docs.modular.com/max/get-started Creates a Python virtual environment named '.venv/quickstart' using the 'venv' module and then activates it. This isolates project dependencies. ```shell python3 -m venv .venv/quickstart \ && source .venv/quickstart/bin/activate ``` -------------------------------- ### Install Conda and Initialize Source: https://docs.modular.com/max/packages Installs Miniconda using Homebrew and initializes conda for shell interaction. This is a prerequisite for using conda package manager. ```shell brew install miniconda conda init conda init zsh ``` -------------------------------- ### Create project folder for pip Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Creates a new directory named 'example-project' and changes the current directory to it. This is the first step in setting up a project using pip. ```bash mkdir example-project && cd example-project ``` -------------------------------- ### Run MAX Addition Graph Example in Python Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python This Python script defines input NumPy arrays, calls the `add_tensors` function (which executes a MAX graph), and prints the result. It requires the NumPy library. The output shows the result of the addition operation performed by the MAX graph. ```python if __name__ == "__main__": input0 = np.array([1.0], dtype=np.float32) input1 = np.array([1.0], dtype=np.float32) result = add_tensors(input0, input1) print("result:", result) ``` -------------------------------- ### Benchmark LLM Endpoint with MAX CLI Source: https://docs.modular.com/max/get-started Benchmarks the performance of a local LLM endpoint using the 'max' CLI. This command is configured for text-to-text inference with the Gemma 3 model, specifying dataset, prompt length, and output length parameters. ```bash max benchmark \ --model google/gemma-3-27b-it \ --backend modular \ --endpoint /v1/chat/completions \ --dataset-name sonnet \ --num-prompts 500 \ --sonnet-input-len 550 \ --output-lengths 256 \ --sonnet-prefix-len 200 ``` -------------------------------- ### Get Pointer to First Element (as_ref) Source: https://docs.modular.com/mojo/std/memory/span/Span Gets a Pointer to the first element of the Span, providing a reference to the start of the data. ```Swift func as_ref(self) -> Pointer ``` -------------------------------- ### Initialize Project with uv Source: https://docs.modular.com/max/serve/offline-inference Initializes a new project named 'offline-quickstart' using uv and navigates into the project directory. This sets up the project structure for uv. ```shell uv init offline-quickstart && cd offline-quickstart ``` -------------------------------- ### Get Start and End for Partitions Source: https://docs.modular.com/mojo/kernels/nn/mha_fa3_utils/MHAPosition Retrieves the starting and ending indices for a given partition, useful for segmenting data. ```APIDOC ## get_start_and_end_for_partitions ### Description Retrieves the starting and ending indices for a given partition, useful for segmenting data. ### Method Not specified (likely internal or a method of a class) ### Endpoint Not applicable (this appears to be a function signature rather than a REST endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **Tuple** (Tuple[UInt32, UInt32]) - A tuple containing the start and end indices as unsigned 32-bit integers. #### Response Example None ``` -------------------------------- ### Create a "Hello, World" Program in Mojo Source: https://docs.modular.com/mojo/manual/get-started Defines a simple Mojo program named 'life.mojo' that includes a 'main' function to print 'Hello, World!' to the console. This serves as a basic entry point for Mojo programs. ```mojo # My first Mojo program! def main(): print("Hello, World!") ``` -------------------------------- ### Install pixi and Initialize Project Source: https://docs.modular.com/max/serve/lora-adapters These commands demonstrate installing the pixi package manager and initializing a new project with specified conda channels. This is the first step in setting up an environment for LoRA adapters using pixi. ```bash curl -fsSL https://pixi.sh/install.sh | sh ``` ```bash pixi init lora-adapter \ -c https://conda.modular.com/max-nightly/ -c conda-forge \ && cd lora-adapter ``` -------------------------------- ### StringSlice Length Example (Mojo) Source: https://docs.modular.com/mojo/std/collections/string/string_slice/StringSlice Example demonstrating how to get the byte length and Unicode codepoint length of a StringSlice. It highlights the difference for non-ASCII characters. ```mojo from testing import assert_equal var s_unicode = StringSlice("ನಮಸ್ಕಾರ") assert_equal(len(s_unicode), 21) # Byte length assert_equal(len(s_unicode.codepoints()), 7) # Codepoint length var s_ascii = StringSlice("abc") assert_equal(len(s_ascii), 3) # Byte length assert_equal(len(s_ascii.codepoints()), 3) # Codepoint length ``` -------------------------------- ### Initialize Pixi Project Source: https://docs.modular.com/max/inference/text-to-text This command initializes a new Pixi project named 'chat-quickstart'. It specifies the conda channels to use for package resolution, including the MAX nightly channel and conda-forge. This sets up the project for installing MAX and its dependencies. ```bash pixi init chat-quickstart \ -c https://conda.modular.com/max-nightly/ -c conda-forge \ && cd chat-quickstart ``` -------------------------------- ### Activate conda environment Source: https://docs.modular.com/max/get-started Activates the conda environment named 'quickstart'. Once activated, commands executed in the terminal will use the packages and Python interpreter installed within this environment. ```shell conda activate quickstart ``` -------------------------------- ### Install uv and Initialize PyTorch Project Source: https://docs.modular.com/max/develop/custom-kernels-pytorch Installs the uv package manager and initializes a new PyTorch project. It then creates and activates a virtual environment, installing required packages using uv. ```bash curl -LsSf https://astral.sh/uv/install.sh | sh uv init pytorch_custom_ops && cd pytorch_custom_ops uv venv && source .venv/bin/activate uv pip install modular torch pillow numpy \ --index-url https://dl.modular.com/public/nightly/python/simple/ \ --prerelease allow ``` -------------------------------- ### Install pip and Initialize PyTorch Project Source: https://docs.modular.com/max/develop/custom-kernels-pytorch Creates a project directory and virtual environment using standard Python tools. It then installs modular, PyTorch, Pillow, and NumPy using pip with specified index URLs for nightly or stable releases. ```bash mkdir pytorch_custom_ops && cd pytorch_custom_ops python3 -m venv .venv/pytorch_custom_ops && source .venv/pytorch_custom_ops/bin/activate pip install --pre modular torch pillow numpy \ --index-url https://dl.modular.com/public/nightly/python/simple/ ``` ```bash pip install modular torch pillow numpy \ --extra-index-url https://modular.gateway.scarf.sh/simple/ ``` -------------------------------- ### Activate pixi shell environment Source: https://docs.modular.com/max/develop/get-started-with-max-graph-in-python Starts a new shell session within the pixi-managed virtual environment. This ensures that all subsequent commands have access to the project's dependencies. ```bash pixi shell ``` -------------------------------- ### Check GPU Availability and Get Device Context in Mojo Source: https://docs.modular.com/mojo/manual/gpu/intro-tutorial A Mojo program that checks for a compatible GPU using `has_accelerator()` and obtains a `DeviceContext` if available, printing the GPU's name. ```mojo from gpu.host import DeviceContext from sys import has_accelerator def main(): @parameter if not has_accelerator(): print("No compatible GPU found") else: ctx = DeviceContext() print("Found GPU:", ctx.name()) ``` -------------------------------- ### Uninstall Modular with Conda Source: https://docs.modular.com/max/packages Removes the 'modular' package and its associated dependencies from your Conda environment. ```bash conda remove modular ```