{"id":28719131,"url":"https://github.com/moinfra/sylvan","last_synced_at":"2026-06-14T21:32:16.751Z","repository":{"id":298463570,"uuid":"999335495","full_name":"moinfra/sylvan","owner":"moinfra","description":"🌳 An educational modern C++ deep learning framework supporting CUDA","archived":false,"fork":false,"pushed_at":"2025-06-11T07:39:55.000Z","size":126,"stargazers_count":59,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-26T03:26:59.824Z","etag":null,"topics":["autograd","cuda","deep-learning-framework","dnn","machine-learning","transformer"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moinfra.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-10T05:24:00.000Z","updated_at":"2025-08-19T20:15:48.000Z","dependencies_parsed_at":"2025-06-11T08:44:19.430Z","dependency_job_id":"af53a9e7-2c90-4900-9822-0b2178b21606","html_url":"https://github.com/moinfra/sylvan","commit_stats":null,"previous_names":["moinfra/sylvan"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/moinfra/sylvan","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinfra%2Fsylvan","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinfra%2Fsylvan/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinfra%2Fsylvan/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinfra%2Fsylvan/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moinfra","download_url":"https://codeload.github.com/moinfra/sylvan/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moinfra%2Fsylvan/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34339194,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-14T02:00:07.365Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autograd","cuda","deep-learning-framework","dnn","machine-learning","transformer"],"created_at":"2025-06-15T06:00:15.905Z","updated_at":"2026-06-14T21:32:16.732Z","avatar_url":"https://github.com/moinfra.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sylvan 🌲\n\n🌍 [中文文档](项目介绍.md)\n\n![Build Status](https://github.com/pluveto/sylvan/actions/workflows/ci.yml/badge.svg)\n\nSylvan is an educational, modern C++ deep learning framework built from scratch. It supports CUDA for high-performance GPU computing and Bazel for a robust build system. The main goal of this project is to help developers get a deep, practical understanding of how AI frameworks operate under the hood.\n\nThe core components of this framework are implemented in **under 5000 lines of C++/CUDA code**, making it a concise and approachable codebase for learning.\n\nThis project is developed with a \"composition over inheritance\" philosophy, favoring a functional-style API, which promotes modularity, reusability, and testability by avoiding complex class hierarchies and enabling easier combination of operations. The codebase is very easy to understand and maintain.\n\n## Core Philosophy\n\n- **Modern C++:** Utilizes modern C++ features for clean, safe, and expressive code.\n- **CUDA-First:** All core computations are designed to run on the GPU. No CPU fallback is planned to maintain focus.\n- **Function-Style API:** Operations are free functions (`ops::add(a, b)`) rather than member functions (`a.add(b)`), promoting composition and testability.\n- **No Inheritance for Layers/Ops:** Avoids complex class hierarchies.\n- **Bazel with Bzlmod:** A modern, reproducible, and scalable build system.\n\n## Features \u0026 Roadmap\n\n- [x] `sylvan_tensor` library for core tensor operations (creation, element-wise ops, matmul, sum, reshape, transpose, slice, fill, uniform initialization, ReLU, Softmax, LayerNorm, Embedding lookup)\n- [ ] Advanced GPU Memory Management (Allocator/Pool) (Basic RAII via `std::shared_ptr` for `Tensor` data is implemented)\n- [x] `sylvan_core` library with:\n  - [x] Dynamic Computation Graph\n  - [x] Autograd Engine (backward pass for all implemented ops)\n  - [x] Basic Layers (Linear, ReLU, LayerNorm, Embedding)\n  - [x] Attention Mechanisms (Multi-Head Attention, Scaled Dot-Product Attention)\n  - [x] Transformer Architecture (Encoder, Decoder, Full Transformer)\n  - [x] Optimizers (SGD, Adam)\n- [ ] Convolutional Layers (Conv2D, MaxPooling) using cuDNN\n- [ ] `sylvan_infer` library for optimized inference\n- [ ] Model serialization (saving/loading weights)\n- [ ] Dataloader (multiple formats, parallelly)\n\n## Code Structure \u0026 Learning Focus\n\nSylvan's design prioritizes clarity and a hands-on understanding of deep learning internals. The codebase is extensively commented, especially in the core `sylvan/core` and `sylvan/tensor` directories. Each `Variable` operation, neural network layer, and GPU kernel includes detailed explanations of its purpose, parameters, and mathematical derivation. This focus on documentation aims to provide a clear roadmap for anyone looking to delve into the foundational concepts of modern AI frameworks.\n\n## Dependencies\n\n- CUDA Toolkit 11.0 or later (configured via `$CUDA_PATH`)\n- Bazel 8.2.1 or later\n\n## Building the Project\n\nThis project uses Bazel. Ensure you have a recent version of Bazel and the NVIDIA CUDA Toolkit installed.\n\n1. **Clone the repository:**\n\n    ```bash\n    git clone https://github.com/pluveto/sylvan.git\n    cd sylvan\n    ```\n\n2. **Sync dependencies (first time only):**\n\n    ```bash\n    bazel mod tidy\n    ```\n\n3. **Build all targets:**\n    All CUDA-related build flags are managed via the `.bazelrc` file.\n\n    ```bash\n    bazel build --config=cuda //...\n    ```\n\n4. **Run all tests:**\n\n    ```bash\n    bazel test --config=cuda //...\n    ```\n\n5. **Run an example:**\n\n    ```bash\n    # Run a linear regression example\n    bazel run --config=cuda //examples:linear_regression\n    # Run a transformer example\n    bazel run --config=cuda //examples:number_translator\n    ```\n\n## Directory Structure\n\n- `sylvan/`: Main source code.\n  - `tensor/`: The core tensor library. Doesn't know about autograd.\n  - `core/`: The deep learning framework (autograd, layers, optimizers).\n  - `infer/`: (Future) The inference-only library.\n- `tests/`: Unit tests for all libraries (using GTest).\n- `examples/`: Standalone examples showing how to use the framework.\n\nRun `CC=clang bazel run @hedron_compile_commands//:refresh_all` to generate a compilation database for your editor.\n\nInstall `Nsight Visual Studio Code Edition` for better debugging experience.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoinfra%2Fsylvan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoinfra%2Fsylvan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoinfra%2Fsylvan/lists"}