{"id":23064206,"url":"https://github.com/jamormoussa/nanotorch","last_synced_at":"2025-08-21T09:32:13.228Z","repository":{"id":216890792,"uuid":"742630806","full_name":"JamorMoussa/NanoTorch","owner":"JamorMoussa","description":"NanoTorch is Deep Learning Library from scratch using Numpy and Math.","archived":false,"fork":false,"pushed_at":"2024-07-08T11:27:10.000Z","size":2999,"stargazers_count":20,"open_issues_count":5,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-03T20:06:08.875Z","etag":null,"topics":["nanotoch","nanotorch","numpy","python","pytorch"],"latest_commit_sha":null,"homepage":"https://jamormoussa.github.io/NanoTorch/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JamorMoussa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-01-12T23:00:56.000Z","updated_at":"2025-04-20T06:14:21.000Z","dependencies_parsed_at":"2024-01-19T23:26:08.846Z","dependency_job_id":"9e5a6721-0761-4ed0-844e-cfd60401f2d2","html_url":"https://github.com/JamorMoussa/NanoTorch","commit_stats":null,"previous_names":["jamormoussa/neuranet","jamormoussa/nanotorch"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/JamorMoussa/NanoTorch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamorMoussa%2FNanoTorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamorMoussa%2FNanoTorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamorMoussa%2FNanoTorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamorMoussa%2FNanoTorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JamorMoussa","download_url":"https://codeload.github.com/JamorMoussa/NanoTorch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JamorMoussa%2FNanoTorch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271455614,"owners_count":24762759,"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","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"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":["nanotoch","nanotorch","numpy","python","pytorch"],"created_at":"2024-12-16T04:17:12.650Z","updated_at":"2025-08-21T09:32:12.899Z","avatar_url":"https://github.com/JamorMoussa.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![/docs/images/logo.png](https://raw.githubusercontent.com/JamorMoussa/NanoTorch/main/docs/images/logo.png)\n\n\n\n# NanoTorch\n\n**NanoTorch** is a deep learning library (micro-framework) inspired by the PyTorch framework, which \nI created using only **Math** and **Numpy** :). My purpose here is not to create a powerful deep \nlearning framework (maybe in the future), but solely to understand how deep learning frameworks like PyTorch and TensorFlow work behind the scenes.\n\n## Neural Networks:\n\nLet's explore an example of building a simple neural network (essentially a Linear Regression model) with **NanoTorch**:\n\n```python\nimport nanotorch as nnt\nimport nanotorch.nn as nn \n```\n\nLet's build a simple model:\n\n```python\nclass MLPModel(nn.Module):\n\n    def __init__(self):\n\n        self.fc = nn.Sequential(\n            nn.Linear(3, 3),\n            nn.Sigmoid(),\n            nn.Linear(3, 5),\n            nn.Sigmoid(), \n            nn.Linear(5, 1)\n        )\n\n    def forward(self, input: nnt.Tensor) -\u003e nnt.Tensor:\n        return self.fc(input)\n```\nLet's generate a simple dataset, using the `nn.rand` function and the `nnt.dot` operation:\n\n```python\nX = nnt.rand(100, 3)\ny = nnt.dot(X, nnt.Tensor([1, -2, 3]).T)    \n```\n\nNow, let's create an instance of `MLPModel`\n```python\nmodel = MLPModel()\n```\n\nWe are dealing with regression task. So, the `nn.MSELoss` is chosen\n\n```python\nmse = nn.MSELoss(model.layers())\n```\n\nLet's define the stochastic gradient descent optimizer\n\n```python\nopt = nnt.optim.SGD(model.layers(), lr=0.001)\n```\n\nFinally, The training loop\n\n```python\nfor epoch in range(30):\n\n    for xi, yi in zip(X, y):\n\n        opt.zero_grad()\n\n        y_predi = model(nnt.Tensor(xi))\n\n        loss = mse(y_predi, nnt.Tensor(yi))\n\n        loss.backward()\n\n        opt.step()\n\nprint(model.layers()[0].parameter)\n```\n\nThe output is as follows:\n\n```\n[[1.00772484]\n [1.98651816]\n [3.04503581]]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamormoussa%2Fnanotorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamormoussa%2Fnanotorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamormoussa%2Fnanotorch/lists"}