{"id":32955140,"url":"https://github.com/ahoynodnarb/minidiff","last_synced_at":"2025-11-16T19:01:06.743Z","repository":{"id":297755766,"uuid":"997683875","full_name":"ahoynodnarb/minidiff","owner":"ahoynodnarb","description":"Miniature automatic differentiation library","archived":false,"fork":false,"pushed_at":"2025-09-15T03:47:21.000Z","size":199,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-09-15T05:39:55.486Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ahoynodnarb.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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-06-07T00:50:06.000Z","updated_at":"2025-09-15T03:47:24.000Z","dependencies_parsed_at":"2025-06-07T09:21:49.866Z","dependency_job_id":"93139792-e209-4fcc-8d85-d16dfb8cf65f","html_url":"https://github.com/ahoynodnarb/minidiff","commit_stats":null,"previous_names":["ahoynodnarb/minidiff"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ahoynodnarb/minidiff","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahoynodnarb%2Fminidiff","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahoynodnarb%2Fminidiff/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahoynodnarb%2Fminidiff/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahoynodnarb%2Fminidiff/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahoynodnarb","download_url":"https://codeload.github.com/ahoynodnarb/minidiff/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahoynodnarb%2Fminidiff/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284759739,"owners_count":27058842,"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-11-16T02:00:05.974Z","response_time":65,"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":[],"created_at":"2025-11-12T22:00:41.101Z","updated_at":"2025-11-16T19:01:06.734Z","avatar_url":"https://github.com/ahoynodnarb.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":["General-Purpose Machine Learning"],"readme":"# minidiff: A NumPy-like Reverse-Mode Automatic Differentiation Engine\n\nA lightweight automatic differentiation library with PyTorch-like API, supporting higher-order gradients and eager memory management. \nDesigned as a drop-in replacement for NumPy with readability and clarity as a top priority.\n\nThis codebase does assume the reader has some existing requisite knowledge about multivariable calculus and linear algebra, but it's meant to be as readable as possible with that in mind. You can find great resources for both of those topics pretty much anywhere on the internet!\n\n## Usage\nFinding partial derivatives for almost any function is pretty simple, just:\n\nDefine some variables\n```\nx = md.Tensor([[0, 2, -2, 1], [-1, -1, -2, -2]], allow_grad=True)\ny = md.Tensor([[2, 3, 4, 5], [0, -1, -3, 2]], allow_grad=True)\n```\nRun a calculation\n```\nf = 2 * y * md.sin(x) - x**2\n```\nAnd call `backward()`\n```\nf.backward(allow_higher_order=True)\n# first order partial derivatives\n# df/dx\nprint(x.grad)\n# df/dy\nprint(y.grad)\n```\nIf you want to go a little deeper and compute higher order partial derivatives, it's as simple as just doing a backward pass on the gradient tensors\n```\nx.grad.backward()\nprint(\"second order\")\n# now d^2f/dx^2\nprint(x.grad)\n# now d^2f/dxdy\nprint(y.grad)\n```\n## Custom Functions\nImplementing your own differentiable operations is also pretty simple. \n\nHelper functions like `create_op_func()` and `as_minidiff()` automatically wrap backend functions as minidiff functions and manage computation graphs, respectively. \n\nSee [`minidiff/ops/definitions.py`](https://github.com/ahoynodnarb/minidiff/blob/master/minidiff/ops/definitions.py) for some examples.\n\n## Project Structure\nFeel free to explore around the repo, it's structured as follows:\n\n[`minidiff/tensor.py`](https://github.com/ahoynodnarb/minidiff/blob/master/minidiff/tensor.py): Contains all the basic tensor code which includes a few convenient tensor creation functions and the actual backward pass\n\n[`minidiff/topology.py`](https://github.com/ahoynodnarb/minidiff/blob/master/minidiff/topology.py): The `FuncNode` class is defined here; it mostly acts as a dataclass for graph nodes, but also handles gradient accumulation\n\n[`minidiff/typing.py`](https://github.com/ahoynodnarb/minidiff/blob/master/minidiff/typing.py): Just extra types for convenience to keep type hinting clean and readable\n\n[`minidiff/utils.py`](https://github.com/ahoynodnarb/minidiff/blob/master/minidiff/utils.py): A few utilities used throughout the codebase ranging from finite-difference testing to a graph visualization tool\n\n[`minidiff/ops/definitions.py`](https://github.com/ahoynodnarb/minidiff/blob/master/minidiff/ops/definitions.py): Every operation exported by minidiff is defined here, including their forward and backward passes\n\n[`minidiff/ops/wrapping.py`](https://github.com/ahoynodnarb/minidiff/blob/master/minidiff/ops/wrapping.py): This file mostly contains code that allows wrapping backend functions as `Tensor` functions and automatic differentiability to those resulting `Tensor` functions\n\n[`minidiff/backend/`](https://github.com/ahoynodnarb/minidiff/blob/master/minidiff/backend): Submodule containing logic for selecting a suitable backend and exporting functions from the backend. Currently contains CuPy, NumPy, and MLX","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahoynodnarb%2Fminidiff","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahoynodnarb%2Fminidiff","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahoynodnarb%2Fminidiff/lists"}