### Run vLLM Server Example Source: https://github.com/tenstorrent/tt-metal/blob/main/models/demos/t3000/llama3_70b/README.md Executes the example server script provided by vLLM for Tenstorrent. This script starts the model serving endpoint. ```python python vllm/examples/server_example_tt.py ``` -------------------------------- ### Install `add` Example Directory Source: https://github.com/tenstorrent/tt-metal/blob/main/ttnn/examples/CMakeLists.txt This CMake snippet configures the installation of the `add` directory, which contains example files, to a specific destination within the installed package. It specifies the component `ttnn-examples` for installation and notes a temporary workaround for a documented issue with installing into the `doc` directory. ```cmake install( DIRECTORY add DESTINATION "${CMAKE_INSTALL_DATADIR}/tt-nn/examples" COMPONENT ttnn-examples ) ``` -------------------------------- ### Bash Script: Build and Run tt-metal Programming Examples Source: https://github.com/tenstorrent/tt-metal/blob/main/docs/source/tt-metalium/tt_metal/examples/eltwise_binary.rst This script demonstrates how to build and execute the tt-metal programming examples. It sets the TT_METAL_HOME environment variable and then calls the build script. The example execution command is also provided. Ensure TT_METAL_HOME points to your tt-metal installation. ```bash export TT_METAL_HOME= ./build_metal.sh --build-programming-examples # To run the example ./build/programming_examples/metal_example_eltwise_binary ``` -------------------------------- ### CMake: Install Programming Examples to Data Directory Source: https://github.com/tenstorrent/tt-metal/blob/main/tt_metal/programming_examples/CMakeLists.txt This CMake command installs programming example directories to the `${CMAKE_INSTALL_DATADIR}/tt-metalium/examples` path. It targets specific example subdirectories and excludes files within any `/kernels/` directory from this installation set. This is intended for the 'metalium-examples' component. ```cmake install( DIRECTORY add_2_integers_in_compute add_2_integers_in_riscv eltwise_binary eltwise_sfpu hello_world_compute_kernel hello_world_datamovement_kernel hello_world_datatypes_kernel loopback matmul shard_data_rm NoC_tile_transfer sfpu_eltwise_chain custom_sfpi_add custom_sfpi_smoothstep tests DESTINATION "${CMAKE_INSTALL_DATADIR}/tt-metalium/examples" COMPONENT metalium-examples REGEX "/kernels/" EXCLUDE ) ``` -------------------------------- ### Run tt-metal Programming Example Source: https://github.com/tenstorrent/tt-metal/blob/main/INSTALLING.md Executes a basic programming example using the ttnn module to verify the installation. This command attempts to run an operation on the device. ```python python3 -m ttnn.examples.usage.run_op_on_device ``` -------------------------------- ### Serving the Model with vLLM Source: https://github.com/tenstorrent/tt-metal/blob/main/models/demos/t3000/llama3_70b/README.md Instructions for installing vLLM and running the Tenstorrent-compatible server for the Llama3.1-70B model. ```APIDOC ## Serving the Model with vLLM ### Installation 1. Complete Step 1 and Step 2 of [Running the Demo from TT-Metalium](#running-the-demo-from-tt-metalium). 2. Install vLLM for Tenstorrent: ```bash # Installing from within `tt-metal` export VLLM_TARGET_DEVICE="tt" git clone https://github.com/tenstorrent/vllm.git cd vllm git checkout TT_VLLM_COMMIT_SHA_OR_TAG pip install -e . cd .. ``` > **Note:** Replace `TT_VLLM_COMMIT_SHA_OR_TAG` with the specific vLLM Release version from the [README](/README.md#llms). ### Running the Server Start the vLLM server with the Tenstorrent backend: ```bash python vllm/examples/server_example_tt.py ``` ### Interacting with the Server Send requests to the running server using `curl`: ```bash curl http://localhost:8000/v1/completions \ -H "Content-Type: application/json" \ -d '{ "model": "meta-llama/Meta-Llama-3.1-70B", "prompt": "Write a poem about RISC-V", "max_tokens": 128, "temperature": 1, "top_p": 0.9, "top_k": 10, "stream": false }' ``` #### Request Body Example ```json { "model": "meta-llama/Meta-Llama-3.1-70B", "prompt": "Write a poem about RISC-V", "max_tokens": 128, "temperature": 1, "top_p": 0.9, "top_k": 10, "stream": false } ``` #### Success Response (200) The server will return a JSON object containing the completion. The exact fields may vary based on the vLLM version and server configuration, but typically include: - **`id`** (string) - Unique identifier for the completion. - **`object`** (string) - Type of the object, e.g., "text_completion". - **`created`** (integer) - Unix timestamp of when the completion was created. - **`model`** (string) - The model used for the completion. - **`choices`** (array) - An array of completion choices. - **`text`** (string) - The generated text. - **`index`** (integer) - The index of the choice. - **`logprobs`** (null or object) - Log probabilities for the generated tokens (if enabled). - **`finish_reason`** (string) - The reason the completion finished (e.g., "stop", "length"). - **`usage`** (object) - Usage statistics for the request. - **`prompt_tokens`** (integer) - Number of tokens in the prompt. - **`completion_tokens`** (integer) - Number of tokens in the completion. - **`total_tokens`** (integer) - Total number of tokens. ``` -------------------------------- ### CMake: Install Kernels to Tenstorrent Directory Source: https://github.com/tenstorrent/tt-metal/blob/main/tt_metal/programming_examples/CMakeLists.txt This CMake command installs specific programming example directories, primarily containing kernels, to the `${CMAKE_INSTALL_DATADIR}/tenstorrent/kernels` path. It uses `FILES_MATCHING` with a `REGEX` to ensure only files within `/kernels/` are installed, designated for the 'metalium-examples' component. ```cmake install( DIRECTORY add_2_integers_in_compute add_2_integers_in_riscv eltwise_binary eltwise_sfpu hello_world_compute_kernel hello_world_datamovement_kernel hello_world_datatypes_kernel loopback matmul shard_data_rm NoC_tile_transfer sfpu_eltwise_chain custom_sfpi_add custom_sfpi_smoothstep DESTINATION "${CMAKE_INSTALL_DATADIR}/tenstorrent/kernels" COMPONENT metalium-examples FILES_MATCHING REGEX "/kernels/" ) ``` -------------------------------- ### Mesh Setup for TT-Metal Program Source: https://github.com/tenstorrent/tt-metal/blob/main/tt_metal/programming_examples/loopback/dram_loopback.md Initializes a 1x1 mesh device, obtains the command queue, defines workload parameters, and creates a TT-Metal program. This sets the foundation for executing operations on the mesh. ```cpp constexpr int device_id = 0; auto mesh_device = distributed::MeshDevice::create_unit_mesh(device_id); distributed::MeshCommandQueue& cq = mesh_device->mesh_command_queue(); distributed::MeshWorkload workload; distributed::MeshCoordinateRange device_range = distributed::MeshCoordinateRange(mesh_device->shape()); Program program = CreateProgram(); ``` -------------------------------- ### Install TTNN Example Library (CMake) Source: https://github.com/tenstorrent/tt-metal/blob/main/ttnn/cpp/ttnn/operations/examples/CMakeLists.txt Installs the ttnn_op_examples library as a shared library, associated with the 'tar' component. ```cmake install(TARGETS ttnn_op_examples LIBRARY COMPONENT tar) ``` -------------------------------- ### Tracy Example: Setup Project Directory Structure Source: https://github.com/tenstorrent/tt-metal/blob/main/tech_reports/MetalProfiler/metal-profiler.md This illustrates the recommended directory structure for a project incorporating the Tracy profiler. It includes directories for third-party dependencies, headers, source files, and the main CMake configuration. ```text - project/ - third_party/ - tracy/ - include/ - hellolib.hpp - CMakeLists.txt - main.cpp - hellolib.cpp ``` -------------------------------- ### Install vLLM for Tenstorrent Source: https://github.com/tenstorrent/tt-metal/blob/main/models/demos/t3000/llama3_70b/README.md Installs the vLLM library with Tenstorrent-specific configurations. Ensure you are within the `tt-metal` directory and have set the target device. This requires cloning the vLLM repository and checking out a specific commit or tag. ```bash export VLLM_TARGET_DEVICE="tt" git clone https://github.com/tenstorrent/vllm.git cd vllm git checkout TT_VLLM_COMMIT_SHA_OR_TAG pip install -e . cd .. ``` -------------------------------- ### Example Training Configuration (YAML) Source: https://github.com/tenstorrent/tt-metal/blob/main/tt-train/configs/README.md Demonstrates a typical training configuration block in YAML format. This includes project settings, optimization parameters, and paths to model and data files. ```yaml training_config: project_name: "my_training_project" model_type: "llama" seed: 5489 batch_size: 8 gradient_accumulation_steps: 8 num_epochs: 1 max_steps: 5000 learning_rate: 0.0003 weight_decay: 0.01 use_moreh_adamw: true use_kahan_summation: false use_clip_grad_norm: false clip_grad_norm_max_norm: 1.0 model_config: "configs/model_configs/tinyllama.yaml" data_path: "data/my_dataset.txt" scheduler_type: "warmup_linear" tokenizer_type: "bpe" ``` -------------------------------- ### Complete Training Configuration Example (YAML) Source: https://github.com/tenstorrent/tt-metal/blob/main/tt-train/configs/README.md A comprehensive YAML configuration file encompassing all training parameters, device settings, and optional multihost configuration. This serves as a template for setting up a full training run. ```yaml # Complete training configuration file training_config: project_name: "shakespeare_training" seed: 5489 model_save_interval: 500 batch_size: 8 gradient_accumulation_steps: 8 num_epochs: 1 max_steps: 5000 learning_rate: 0.0003 weight_decay: 0.01 use_moreh_adamw: true use_kahan_summation: false use_clip_grad_norm: false clip_grad_norm_max_norm: 1.0 model_config: "configs/model_configs/tinyllama.yaml" data_path: "data/shakespeare.txt" scheduler_type: "warmup_linear" tokenizer_type: "char" device_config: enable_tp: true mesh_shape: [1, 32] device_ids: [] # Optional multihost configuration (separate file) multihost_config: enabled: false num_workers: 1 socket_type: "mpi" ``` -------------------------------- ### Mesh Setup for TT-Metal Compute Kernel Source: https://github.com/tenstorrent/tt-metal/blob/main/tt_metal/programming_examples/hello_world_compute_kernel/hello_world_compute.md Initializes a 1x1 mesh device, retrieves the command queue, defines a workload and device range, and creates a program object. This is a prerequisite for launching any compute kernel. ```cpp constexpr CoreCoord core = {0, 0}; int device_id = 0; auto mesh_device = distributed::MeshDevice::create_unit_mesh(device_id); distributed::MeshCommandQueue& cq = mesh_device->mesh_command_queue(); distributed::MeshWorkload workload; distributed::MeshCoordinateRange device_range = distributed::MeshCoordinateRange(mesh_device->shape()); Program program = CreateProgram(); ``` -------------------------------- ### Device and Program Setup in TT-Metal Source: https://github.com/tenstorrent/tt-metal/blob/main/tech_reports/prog_examples/NoC_tile_transfer/NoC_tile_transfer.md Initializes the TT-Metal mesh device, command queue, workload, device range, and creates a program object. This is a foundational step for any TT-Metal application. ```cpp std::shared_ptr mesh_device = distributed::MeshDevice::create_unit_mesh(0); distributed::MeshCommandQueue& cq = mesh_device->mesh_command_queue(); distributed::MeshWorkload workload; distributed::MeshCoordinateRange device_range = distributed::MeshCoordinateRange(mesh_device->shape()); Program program = CreateProgram(); ``` -------------------------------- ### TT-Metal Device and Program Setup Source: https://github.com/tenstorrent/tt-metal/blob/main/tech_reports/prog_examples/sfpu_eltwise_chain/sfpu_eltwise_chain.md Initializes the TT-Metal mesh device, command queue, workload, device range, and creates a program object. This sets up the fundamental components for launching computations on the hardware. ```cpp std::shared_ptr mesh_device = distributed::MeshDevice::create_unit_mesh(0); distributed::MeshCommandQueue& cq = mesh_device->mesh_command_queue(); distributed::MeshWorkload workload; distributed::MeshCoordinateRange device_range = distributed::MeshCoordinateRange(mesh_device->shape()); distributed::Program program = distributed::CreateProgram(); ``` -------------------------------- ### Training Configuration File Example Source: https://github.com/tenstorrent/tt-metal/blob/main/tt-train/sources/examples/python/multihost/hierarchical_parallel/README.md Example YAML configuration for distributed training, specifying training parameters, multi-host communication settings, and device configurations for DDP and tensor parallelism. ```yaml training_config: steps: 1000 batch_size: 32 gradient_accumulation_steps: 1 num_epochs: 1 multihost_config: enabled: true num_workers: 2 # Number of training worker ranks socket_type: fabric # or mpi device_config: enable_ddp: true # Enable if using multiple devices per worker enable_tp: false # Enable for tensor parallelism mesh_shape: [1, 8] ``` -------------------------------- ### Set PYTHONPATH for Verification Source: https://github.com/tenstorrent/tt-metal/blob/main/INSTALLING.md Sets the PYTHONPATH environment variable to the tt-metal project directory. This is required to run programming examples and verify the installation. ```sh export PYTHONPATH= ``` -------------------------------- ### Install TT-Installer Script (Shell) Source: https://github.com/tenstorrent/tt-metal/blob/main/docs/source/ttnn/ttnn/installing.md Downloads and executes the TT-Installer script for a quick setup of Tenstorrent's software stack. It automatically installs the latest versions of dependencies. Flags can be used to specify versions for SMI, firmware, and KMD. ```shell curl -fsSL https://github.com/tenstorrent/tt-installer/releases/latest/download/install.sh -O chmod +x install.sh ./install.sh --no-install-podman --no-install-metalium-container ``` ```shell ./install.sh \ --smi-version=v3.0.38 \ --fw-version=19.2.0 \ --kmd-version=2.5.0 \ --no-install-podman \ --no-install-metalium-container ``` -------------------------------- ### Build and Run Profiling Example Source: https://github.com/tenstorrent/tt-metal/blob/main/docs/source/tt-metalium/tools/device_program_profiler.rst Builds the programming examples, including the profiler demonstration, and then runs the 'test_full_buffer' application with device profiling enabled. This command sequence allows for testing and observing the device profiler's functionality. ```bash cd $TT_METAL_HOME ./build_metal.sh --build-programming-examples TT_METAL_DEVICE_PROFILER=1 ./build/programming_examples/profiler/test_full_buffer ``` -------------------------------- ### Clone tt-metal Repository Source: https://github.com/tenstorrent/tt-metal/blob/main/INSTALLING.md Clones the tt-metal repository and its submodules. This is the first step to get the project source code. ```sh git clone https://github.com/tenstorrent/tt-metal.git --recurse-submodules ``` -------------------------------- ### Create Programs for Devices Source: https://github.com/tenstorrent/tt-metal/blob/main/tech_reports/TT-Distributed/TT-Distributed-Architecture-1219.md Demonstrates the creation of programs for deployment on compute devices. These programs encapsulate compute kernels, similar to mesh workloads but targeted at individual devices. They specify operations, buffers, and operational parameters. ```cpp std::shared_ptr mul_program = create_binary_program(mul_src_0, mul_src_1, mul_dst, single_tile_size, num_tiles_per_device, BinaryOpType::MUL); std::shared_ptr add_program = create_binary_program(add_src_0, add_src_1, add_dst, single_tile_size, num_tiles_per_device, BInaryOpType::ADD); ``` -------------------------------- ### Bash Commands for Building and Running TT-Metal Example Source: https://github.com/tenstorrent/tt-metal/blob/main/tt_metal/programming_examples/loopback/dram_loopback.md Provides the necessary bash commands to build the TT-Metal programming examples and execute the loopback program. These commands set up the environment and initiate the program's compilation and runtime. ```bash export TT_METAL_HOME=$(pwd) ./build_metal.sh --build-programming-examples ./build/programming_examples/loopback ``` -------------------------------- ### Install tt-train via pip Source: https://github.com/tenstorrent/tt-metal/blob/main/tt-train/INSTALLING.md Installs the tt-train python module using pip. Supports both regular and editable installations, with the editable option being useful for development purposes. ```bash # Regular installation: pip install /path/to/tt-train/ # Editable installation (for development): pip install -e /path/to/tt-train/ ``` -------------------------------- ### Create Configuration Directory Source: https://github.com/tenstorrent/tt-metal/blob/main/tt-train/sources/examples/python/multihost/README.md This command creates a new directory for a custom hardware setup under the 'configurations/' path. It ensures the parent directory exists. ```bash mkdir -p configurations/my_setup ``` -------------------------------- ### Verify tt-train and tt-metal Installation Source: https://github.com/tenstorrent/tt-metal/blob/main/tt-train/INSTALLING.md Confirms that the tt-metal (ttnn) and tt-train (ttml) modules have been successfully installed and are importable within a Python environment. It also shows how to check the installation path of these modules. ```python import ttnn print("successfully imported ttnn") import ttml print("successfully imported ttml") # To check installed locations: import ttnn print(f"ttnn location: {ttnn.__file__}") import ttml print(f"ttml location: {ttml.__file__}") ``` -------------------------------- ### Multi-Command Queue Workflow Example (Python) Source: https://github.com/tenstorrent/tt-metal/blob/main/tech_reports/AdvancedPerformanceOptimizationsForModels/AdvancedPerformanceOptimizationsForModels.md An example illustrating a multi-command queue workflow where one queue (CQ1) handles input writes and another (CQ0) executes programs and reads back outputs. It involves event synchronization to ensure operations are performed in the correct order, optimizing performance by managing tensor residency in L1 and DRAM. ```python # This example uses CQ1 for input writes, and CQ0 for executing programs/reading back the output. # `op_event` signals when the first operation is complete. It reads the input tensor and issues the next write once complete. # `write_event` signals when an input write is complete. It signals that the input tensor can be read. # Allocate the persistent input tensor: input_dram_tensor = ttnn.allocate_tensor_on_device(shape, dtype, layout, device, sharded_dram_mem_config) ``` -------------------------------- ### Create Python Virtual Environment with tt-metal Source: https://github.com/tenstorrent/tt-metal/blob/main/tt-train/INSTALLING.md Sets up a Python virtual environment with necessary dependencies and installs tt-metal in editable mode. This is the recommended method for installing tt-metal when building from source or using the pip installation method. ```bash cd /path/to/tt-metal ./create_venv.sh source python_env/bin/activate ``` -------------------------------- ### Initialize TT-Metal Device and Program Setup Source: https://github.com/tenstorrent/tt-metal/blob/main/tt_metal/programming_examples/add_2_integers_in_compute/add_2_integers_in_compute.md Sets up the TT-Metal device, command queue, workload, and program. It also identifies the specific core (0,0) for execution. This is a standard initialization procedure for TT-Metal programs. ```cpp std::shared_ptr mesh_device = distributed::MeshDevice::create_unit_mesh(0); distributed::MeshCommandQueue& cq = mesh_device->mesh_command_queue(); distributed::MeshWorkload workload; distributed::MeshCoordinateRange device_range = distributed::MeshCoordinateRange(mesh_device->shape()); Program program = CreateProgram(); constexpr CoreCoord core = {0, 0}; ``` -------------------------------- ### Install ttnn_op_reduction Library Components (CMake) Source: https://github.com/tenstorrent/tt-metal/blob/main/ttnn/cpp/ttnn/operations/reduction/CMakeLists.txt Defines the installation rules for the 'ttnn_op_reduction' target. The 'api' file set is installed as a development component, while the 'kernels' file set is installed for runtime use in a specific directory. ```cmake install( TARGETS ttnn_op_reduction FILE_SET api COMPONENT ttnn-dev FILE_SET kernels DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/tt-metalium/ttnn/cpp/ttnn/operations/reduction COMPONENT ttnn-runtime ) ``` -------------------------------- ### Build tt-metal Programming Examples Source: https://github.com/tenstorrent/tt-metal/blob/main/docs/source/tt-metalium/tt_metal/examples/eltwise_sfpu.rst Instructions on how to build the tt-metal programming examples, including the eltwise_sfpu example. This can be achieved by using the '--build-programming-examples' flag with the build script or '-DBUILD_PROGRAMMING_EXAMPLES=ON' with the cmake command. ```bash export TT_METAL_HOME= ./build_metal.sh ./build/programming_examples/metal_example_eltwise_sfpu ``` -------------------------------- ### Install TTNN Python Package Source: https://github.com/tenstorrent/tt-metal/blob/main/docs/source/tt-metalium/installing.md Installs the TTNN Python package using pip. This is the recommended method for quick access to TTNN Python APIs and pre-built AI models. Ensure you have Python and pip installed and configured correctly. ```shell pip install ttnn ``` -------------------------------- ### Set tt-metal Environment Variables Source: https://github.com/tenstorrent/tt-metal/blob/main/tt-train/INSTALLING.md Configures essential environment variables for tt-metal to function correctly. `TT_METAL_HOME` points to the tt-metal installation directory, and `PYTHONPATH` ensures Python can find the installed modules. ```bash export TT_METAL_HOME=/path/to/your/tt-metal export PYTHONPATH=$TT_METAL_HOME:$PYTHONPATH ``` -------------------------------- ### Build and Run TT-Metal SFPU Eltwise Chain Example Source: https://github.com/tenstorrent/tt-metal/blob/main/tech_reports/prog_examples/sfpu_eltwise_chain/sfpu_eltwise_chain.md Commands to build the TT-Metal programming examples and run the specific SFPU eltwise chain executable. Ensure TT_METAL_HOME is set correctly before building. ```bash export TT_METAL_HOME=$(pwd) ./build_metal.sh --build-programming-examples ./build/programming_examples/metal_example_sfpu_eltwise_chain ``` -------------------------------- ### Install TT-Installer with Specific Dependency Versions Source: https://github.com/tenstorrent/tt-metal/blob/main/docs/source/tt-metalium/installing.md This command installs the TT-Installer script with specific versions for SMI, firmware, and KMD. It also includes flags to skip Podman and Metalium container installations. Ensure the specified versions are compatible with your hardware and system requirements. ```shell ./install.sh \ --smi-version=v3.0.38 \ --fw-version=19.2.0 \ --kmd-version=2.5.0 \ --no-install-podman \ --no-install-metalium-container ``` -------------------------------- ### Build and Run DRAM Loopback Example - Bash Source: https://github.com/tenstorrent/tt-metal/blob/main/docs/source/tt-metalium/tt_metal/examples/dram_loopback.rst Instructions to build and run the DRAM Loopback example. This involves setting the TT_METAL_HOME environment variable, building the programming examples using a provided script, and then executing the compiled program. ```bash export TT_METAL_HOME= ./build_metal.sh --build-programming-examples # To run the example ./build/programming_examples/metal_example_loopback ``` -------------------------------- ### Bash Script for Building and Running TT Metal SFPI Add Example Source: https://github.com/tenstorrent/tt-metal/blob/main/docs/source/tt-metalium/tt_metal/examples/custom_sfpi_add.rst This bash script configures the environment and builds the TT Metal programming examples, specifically enabling the custom SFPI add example. It then shows how to execute the compiled program. ```bash export TT_METAL_HOME= ./build_metal.sh --build-programming-examples # To run the example ./build/programming_examples/metal_example_custom_sfpi_add ``` -------------------------------- ### Start Tracy Profiler GUI Source: https://github.com/tenstorrent/tt-metal/blob/main/docs/source/tt-metalium/tools/tracy_profiler.rst Command to launch the Tracy GUI application after installation. This command is used on both Mac and Linux after the respective installation or build steps. ```bash tracy ``` -------------------------------- ### Build and Run TT-Metalium Programming Examples Source: https://github.com/tenstorrent/tt-metal/blob/main/tech_reports/prog_examples/pad_multi_core/pad_multi_core.md Provides bash commands to build the TT-Metalium programming examples and then execute the multi-core padding example. It requires setting the TT_METAL_HOME environment variable. ```bash export TT_METAL_HOME=$(pwd) ./build_metal.sh --build-programming-examples ./build/programming_examples/metal_example_pad_multi_core ``` -------------------------------- ### Install ttnn_op_reduction Target for Runtime (CMake) Source: https://github.com/tenstorrent/tt-metal/blob/main/ttnn/cpp/ttnn/operations/reduction/CMakeLists.txt Installs the 'ttnn_op_reduction' target as a library component for runtime. This ensures that the compiled library is available for deployment. ```cmake install(TARGETS ttnn_op_reduction LIBRARY COMPONENT tar) ``` -------------------------------- ### Install tt-metal via APT Source: https://github.com/tenstorrent/tt-metal/blob/main/tt-train/INSTALLING.md Installs tt-metal (ttnn) using the APT package manager. This method requires adding the Tenstorrent APT repository first. It also includes steps for creating and activating a Python virtual environment. ```bash # Add the Tenstorrent APT repository (if not already added) # Instructions for adding the repository should be provided by Tenstorrent # Install tt-metal (ttnn) sudo apt update sudo apt install ttnn # Create and activate a Python virtual environment python3 -m venv python_env source python_env/bin/activate ``` -------------------------------- ### Tracy Example: Build Project Commands Source: https://github.com/tenstorrent/tt-metal/blob/main/tech_reports/MetalProfiler/metal-profiler.md These commands set up the build environment using CMake and Ninja, enabling Tracy profiling, and then compile the project. The output will be executables and libraries in the 'build/' directory. ```bash mkdir -p build cd build/ cmake -G Ninja -DTRACY_ENABLE=ON .. ninja ``` -------------------------------- ### Install TTNN Example Kernels (CMake) Source: https://github.com/tenstorrent/tt-metal/blob/main/ttnn/cpp/ttnn/operations/examples/CMakeLists.txt Installs the kernel files for the ttnn_op_examples target to a specific destination within the runtime library path, marked for the ttnn-runtime component. ```cmake install( TARGETS ttnn_op_examples FILE_SET kernels DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/tt-metalium/ttnn/cpp/ttnn/operations/examples COMPONENT ttnn-runtime ) ``` -------------------------------- ### Example Usage for Model Development Stages Source: https://github.com/tenstorrent/tt-metal/blob/main/models/demos/deepseek_v3/README.md Provides a Python code example demonstrating the three stages of model development: converting weights, generating operator configurations, and creating the runtime model state. This covers `convert_weights`, `prefill_model_config` (or `decode_model_config`), and `create_state`. ```python # Stage 1: Convert weights and get weight_config (saves to disk in standard format) weight_config = MLP.convert_weights(hf_config, torch_state_dict, Path("weights/mlp"), mesh_device) # Stage 2: Generate operator configs (returns nested dicts with TTNN objects) model_config = MLP.prefill_model_config(hf_config, mesh_device) # Or decode_model_config(hf_config, mesh_device) for decode # Stage 3: Generate the runtime state of the model model_state = MLP.create_state(hf_config, mesh_device) ``` -------------------------------- ### Set Up TTNN Development Environment Source: https://github.com/tenstorrent/tt-metal/blob/main/docs/source/tt-metalium/installing.md This script configures the environment for working with TTNN models. It sets the PYTHONPATH, installs development requirements, and configures the CPU governor for optimal performance. This is typically used when installing from source or for development purposes. ```shell export PYTHONPATH=$(pwd) pip install -r tt_metal/python_env/requirements-dev.txt sudo apt-get install cpufrequtils sudo cpupower frequency-set -g performance ``` -------------------------------- ### Set Runtime Arguments and Enqueue Mesh Workload in C++ Source: https://github.com/tenstorrent/tt-metal/blob/main/docs/source/tt-metalium/tt_metal/examples/eltwise_binary.rst This snippet demonstrates setting runtime arguments for reader, writer, and compute kernels within a program for a specific core. It then constructs a distributed mesh workload, adds the program to it, and enqueues it for execution on the mesh device, followed by finishing the computation. ```cpp SetRuntimeArgs(program, reader, core, {src0_dram_buffer->address(), src1_dram_buffer->address(), n_tiles}); SetRuntimeArgs(program, writer, core, {dst_dram_buffer->address(), n_tiles}); SetRuntimeArgs(program, compute, core, {n_tiles}); distributed::MeshWorkload workload; distributed::MeshCoordinateRange device_range = distributed::MeshCoordinateRange(mesh_device->shape()); workload.add_program(device_range, std::move(program)); distributed::EnqueueMeshWorkload(cq, workload, false); distributed::Finish(cq); ``` -------------------------------- ### Install tt-metalium using Conda Source: https://github.com/tenstorrent/tt-metal/blob/main/INSTALLING.md Installs the tt-metalium package using Conda, creating a new Conda environment named 'metalium'. This method is for users who prefer Conda for environment management and binary installations. It supports Python 3.10, 3.11, and 3.12 and is only available on Linux with glibc 2.34 or newer. ```sh conda create -n metalium python=3.10 tt-metalium -c conda-forge ```