-------------------------------------------- Aidge Core: building blocks of the framework -------------------------------------------- What is ``aidge_core``? ======================= ``aidge_core`` is the foundational module of Aidge, providing the essential building blocks for developping your deep neural networks in a runtime execution mode. It's the angular stone to the entire framework, offering core functionalities to: - **Manage data:** define how data (using **Tensors**) is stored and manipulated. - **Represent AI models:** manage your neural network model as **computational graphs**. - **Manipulate graphs:** enable low-level graph transformation and optimization. While aidge_core is primarily a **C++ library**, Aidge offers **Python bindings** (thanks to Pybind). This lets you programmatically manipulate your models directly from Python, without needing to delve into C++. Dive into core concepts ======================= Here are the core concepts you'll encounter: - **GraphView**: this is the graph representation of your deep learning model. - **Node and Operator**: nodes are the building blocks of the graph, each representing an operation (e.g. an addition, convolution, or activation function). - **Tensor**: the fundamental data structure used by Aidge to represent the inputs, outputs, and weights of your model. GraphView: your deep learning model as a graph ---------------------------------------------- The **GraphView** is Aidge's comprehensive representation of your entire AI model, or a part of it. This directed acyclic graph clearly defines how data flows between operations. **Key characteristics:** - **Node collection management**: contains all Node objects each representing an operation (e.g., Convolution, ReLU, Add) of the model. - **Data flow management**: implicitly manages the connections (edges) between nodes, showing how the output of one node becomes the input of another. - **Optimization hub:** all graph-level optimizations (like fusing of operation or quantization) operate directly on the GraphView. Node: the operational unit -------------------------- A Node within a GraphView represents a single operation in your AI model. **Key characteristics:** - **Operator encapsulation**: a Node wraps an Operator, which defines the actual mathematical function. - **Inputs and outputs management**: each Node has defined inputs (the tensors it expects) and outputs (the tensors it produces). These links between inputs and outputs define implicitly graph structure. - **Attributes configuration**: nodes can have attributes (e.g., kernel size for a convolution) that define how their Operator behaves. - **Name**: each node typically has a unique name for identification and debugging. Operator: the computational logic --------------------------------- An **Operator** defines the abstract computational logic for specific mathematical or logical operations. Operators provide the interface that enables Aidge to understand what computation needs to be performed, while backends provide the actual hardware-specific implementations. **Key characteristics:** - **Operation type**: for example, an Add operator performs element-wise addition, a Conv operator performs a convolution. - **Inputs and outputs**: each operator specify how many inputs it expects, their data types (e.g., float, int), and their categories (e.g., data input, parameter input like weights or biases). It also defines what kind of output (or outputs) it produces. - **Attributes**: many operators have configurable parameters beyond their inputs, such as the kernel size for a convolution, the stride, padding, or whether to enable specific features. These are called attributes. Introducing the MetaOperator ---------------------------- While individual operators define atomic actions, real-world AI models often combine these basic operations into larger, more complex patterns. Think of a "Padded Convolution layer: it's not a single operation but a sequence of padding and convolution. To handle such patterns efficiently, Aidge introduces the **MetaOperator**. A MetaOperator is a **composite operator** that encapsulates an entire **sequence** of simpler, atomic operators. Instead of dealing with each individual operation in a sequence, a MetaOperator allows Aidge to treat this entire sequence as a single, higher-level logical unit. Why is MetaOperator so important? --------------------------------- The MetaOperator plays a critical role in Aidge's ability to optimize and manage complex AI models: 1. **Semantic understanding**: it allows to understand higher-level patterns within a model. Instead of just seeing a collection of low-level math operations, Aidge can recognize that these operations collectively represent a "Batch Normalization" or a "Linear Layer" (if defined as such). 2. **Facilitating optimizations**: - **Graph simplification**: by grouping operations, the GraphView becomes less cluttered, making it easier to analyze and apply transformations (without ever losing the details of elementary operators). - **Targeted optimizations**: backends (the specific hardware implementations) can often provide highly optimized implementations for common patterns. Recognizing these patterns as MetaOperators allows Aidge to swap out the low-level graph for a highly optimized kernel for that pattern on the target hardware. 3. **Modularity and reusability**: common complex patterns can be defined once as MetaOperators and then reused across different models or different parts of the same model. 4. **Debugging and analysis**: when inspecting a model's graph, seeing high-level MetaOperators can make the graph much more readable and understandable for a human user, rather than a vast number of of atomic operations. Introducing the GenericOperator ------------------------------- A **Generic Operator** is a unique type of operator in Aidge that doesn't perform any computation itself. Its primary purpose is to allow you to import models containing operators not natively supported by Aidge's core library or its plugins. Once imported, you can then **replace the Generic Operator with a sequence of known Aidge operators** that achieve the same functionality, or you can **define a custom implementation** for that Generic Operator. This tutorial offers a practical look at how `Generic Operators `__ are used. Tensor: the data representation ------------------------------- A **Tensor** is the fundamental data structure in Aidge for representing any piece of information within your AI model. If you're familiar with other AI frameworks (like NumPy, TensorFlow, or PyTorch), a Tensor is very similar to their array structures. By abstracting the data representation, Aidge can handle Tensors on various hardware platforms. For example, a Tensor might live in CPU memory, or be transferred to a GPU's memory for processing, while still being represented as an Aidge Tensor from a conceptual standpoint. **Key characteristics**: 1. **Shape (Dimensions)**: describes the size of each dimension of the array. 2. **Data Type (DType)**: specifies the type of numbers stored in the tensor (e.g. FLOAT32, INT32, UINT8, BOOL, …). 3. **Data (Values)**: the actual numerical values stored in the multi-dimensional array. 4. **Name (Optional)**: useful for identifying them within the GraphView. Understanding “backends” in Aidge ================================= **Backends** provide the bridge between Aidge's abstract model representation and concrete hardware execution. A backend implements the Operator definition or the Tensor management for specific hardware platforms while maintaining consistent behavior. Prime examples include: - **aidge_backend_cpu (CPU Backend)**: provides Operator implementations for general-purpose CPUs. This is often the default or fallback backend. It utilizes standard CPU instructions and leverage CPU-specific optimizations like multi-threading (OpenMP) for parallel processing where applicable. - **aidge_backend_cuda (CUDA Backend for NVIDIA GPUs)**: provides Operator implementations specifically optimized for NVIDIA GPUs, leveraging the CUDA parallel computing platform. See `backends `__ in action: explore our tutorial! Overview of the core concepts and their relationships ===================================================== .. image:: /source/_static/class_core.png :scale: 70%