{"id":14992131,"url":"https://github.com/elftausend/gradients","last_synced_at":"2025-04-11T03:52:17.735Z","repository":{"id":43406768,"uuid":"476444177","full_name":"elftausend/gradients","owner":"elftausend","description":"Deep Learning library written in Rust (OpenCL, CUDA \u0026 CPU)","archived":false,"fork":false,"pushed_at":"2024-04-02T14:48:00.000Z","size":212,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T03:52:10.577Z","etag":null,"topics":["cpu","cuda","deep-learning","gpu","gpu-acceleration","machine-learning","mlp","neural-networks","opencl","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/elftausend.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}},"created_at":"2022-03-31T19:11:28.000Z","updated_at":"2023-06-01T14:25:29.000Z","dependencies_parsed_at":"2024-04-02T16:03:24.481Z","dependency_job_id":null,"html_url":"https://github.com/elftausend/gradients","commit_stats":{"total_commits":92,"total_committers":2,"mean_commits":46.0,"dds":"0.17391304347826086","last_synced_commit":"7e0aaa2072499c2b1b8bc9246bf2a8c1e28aca99"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elftausend%2Fgradients","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elftausend%2Fgradients/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elftausend%2Fgradients/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elftausend%2Fgradients/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elftausend","download_url":"https://codeload.github.com/elftausend/gradients/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248339261,"owners_count":21087214,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["cpu","cuda","deep-learning","gpu","gpu-acceleration","machine-learning","mlp","neural-networks","opencl","rust"],"created_at":"2024-09-24T15:00:45.735Z","updated_at":"2025-04-11T03:52:17.714Z","avatar_url":"https://github.com/elftausend.png","language":"Rust","funding_links":[],"categories":["Machine Learning"],"sub_categories":[],"readme":"# gradients\n\n[![Crates.io version](https://img.shields.io/crates/v/gradients.svg)](https://crates.io/crates/gradients)\n[![Docs](https://docs.rs/gradients/badge.svg?version=0.3.4)](https://docs.rs/gradients/0.3.4/gradients/)\n\nDeep Learning library using [custos] and [custos-math].\n\nexternal (C) dependencies: OpenCL, CUDA, nvrtc, cublas, a BLAS lib (OpenBLAS, Intel MKL, ...)\n\n[custos]: https://github.com/elftausend/custos\n[custos-math]: https://github.com/elftausend/custos-math\n\n## Installation\n\nThere are two features available that are enabled by default:\n- cuda ... CUDA, nvrtc and cublas must be installed\n- opencl ... OpenCL is needed\n\nIf you deactivate them (add `default-features = false` and provide no additional features), only the CPU device can be used.\n\nFor all feature-configurations, a BLAS library needs to be installed on the system.\n\n```toml\n[dependencies]\ngradients = \"0.3.4\"\n\n# to disable the default features (cuda, opencl) and use an own set of features:\n#gradients = {version = \"0.3.4\", default-features = false, features=[\"opencl\"]}\n```\n\n## MNIST [example] \n\n(if this example does not compile, consider looking [here](https://github.com/elftausend/gradients/blob/main/gradients/examples/mnist.rs))\n\n[example]: https://github.com/elftausend/gradients/blob/main/gradients/examples/mnist.rs\nUse a struct that implements the NeuralNetwork trait (it is implemented via the `network` attribute) to define which layers you want to use:\n\n```rust\nuse gradients::prelude::*;\n\n#[network]\npub struct Network {\n    lin1: Linear\u003c784, 128\u003e,\n    relu1: ReLU,\n    lin2: Linear\u003c128, 10\u003e,\n    relu2: ReLU,\n    lin3: Linear\u003c10, 10\u003e,\n    softmax: Softmax,\n}\n```\nLoad [data] and create an instance of Network:\n\nYou can download the mnist dataset [here](https://www.kaggle.com/datasets/oddrationale/mnist-in-csv).\n\n[data]: https://www.kaggle.com/datasets/oddrationale/mnist-in-csv\n\n```rust\n// let device = gradients::CPU::new(); // use cpu (no framework specific features enabled):\n// let device = gradients::CudaDevice::new(0)?; // use cuda device (cuda feature enabled):\n// use opencl device (opencl feature enabled):\nlet device = CLDevice::new(0)?;\n\nlet mut net = Network::with(\u0026device);\n\nlet loader = CSVLoader::new(true);\nlet loaded_data: CSVReturn\u003cf32\u003e = loader.load(\"PATH/TO/DATASET/mnist_train.csv\")?;\n\nlet mut i = Matrix::from((\n    \u0026device,\n    (loaded_data.sample_count, loaded_data.features),\n    \u0026loaded_data.x,\n));\ni /= 255.;\n\nlet y = Matrix::from((\u0026device, (loaded_data.sample_count, 1), \u0026loaded_data.y));\nlet y = y.onehot();\n```\n\nTraining loop:\n\n```rust\nlet mut opt = Adam::new(0.01);\n\nfor epoch in range(200) {\n    let preds = net.forward(\u0026i);\n    let correct_training = correct_classes(\u0026loaded_data.y.as_usize(), \u0026preds) as f32;\n\n    let loss = cce(\u0026device, \u0026preds, \u0026y);\n    println!(\n        \"epoch: {epoch}, loss: {loss}, training_acc: {acc}\",\n        acc = correct_training / loaded_data.sample_count() as f32\n    );\n\n    let grad = cce_grad(\u0026device, \u0026preds, \u0026y);\n    net.backward(\u0026grad);\n    opt.step(\u0026device, net.params());\n}\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felftausend%2Fgradients","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felftausend%2Fgradients","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felftausend%2Fgradients/lists"}