{"id":21428297,"url":"https://github.com/mlverse/luz","last_synced_at":"2025-04-09T12:06:52.220Z","repository":{"id":39797700,"uuid":"360999065","full_name":"mlverse/luz","owner":"mlverse","description":"Higher Level API for torch","archived":false,"fork":false,"pushed_at":"2024-09-17T14:34:41.000Z","size":17056,"stargazers_count":91,"open_issues_count":16,"forks_count":14,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-02T07:09:59.706Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://mlverse.github.io/luz/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mlverse.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","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":"2021-04-23T20:32:24.000Z","updated_at":"2025-04-02T05:57:29.000Z","dependencies_parsed_at":"2022-09-18T04:41:16.442Z","dependency_job_id":"f02be30a-d657-4f7b-bee7-873479640f81","html_url":"https://github.com/mlverse/luz","commit_stats":{"total_commits":478,"total_committers":5,"mean_commits":95.6,"dds":0.07531380753138073,"last_synced_commit":"1f69203653560b9cebc97fa8d6a15d7d211c8d65"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlverse%2Fluz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlverse%2Fluz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlverse%2Fluz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mlverse%2Fluz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mlverse","download_url":"https://codeload.github.com/mlverse/luz/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248036063,"owners_count":21037092,"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":[],"created_at":"2024-11-22T22:12:31.135Z","updated_at":"2025-04-09T12:06:52.197Z","avatar_url":"https://github.com/mlverse.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# luz\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/mlverse/luz/workflows/R-CMD-check/badge.svg)](https://github.com/mlverse/luz/actions)\n[![Codecov test coverage](https://codecov.io/gh/mlverse/luz/branch/main/graph/badge.svg)](https://app.codecov.io/gh/mlverse/luz?branch=main)\n[![Discord](https://img.shields.io/discord/837019024499277855?logo=discord)](https://discord.com/invite/s3D5cKhBkx)\n[![CRAN status](https://www.r-pkg.org/badges/version/luz)](https://CRAN.R-project.org/package=luz)\n[![](https://cranlogs.r-pkg.org/badges/luz)](https://cran.r-project.org/package=luz)\n\u003c!-- badges: end --\u003e\n\nLuz is a higher level API for torch providing abstractions to allow for much less verbose training loops.\n\nThis package is still under development.\n\nIt is heavily inspired by other higher level frameworks for deep learning, to cite a few:\n\n-   [FastAI](https://docs.fast.ai/): we are heavily inspired by the FastAI library, especially the `Learner` object and the callbacks API.\n\n-   [Keras](https://keras.io/): We are also heavily inspired by Keras, especially callback names. The lightning module interface is similar to `compile`, too.\n\n-   [PyTorch Lightning](https://lightning.ai/pages/open-source/): The idea of the `luz_module` being a subclass of `nn_module` is inspired by the **`LightningModule`** object in lightning.\n\n-   [HuggingFace Accelerate](https://huggingface.co/docs/accelerate/): The internal device placement API is heavily inspired by Accelerate, but is much more modest in features. Currently only CPU and Single GPU are supported.\n\n## Installation\n\nYou can install the released version from CRAN with:\n\n```{.r}\ninstall.packages(\"luz\")\n```\n\nor the development version with:\n\n```{.r}\nremotes::install_github(\"mlverse/luz\")\n```\n\n## Example\n\nLuz lets you take your torch `nn_module` definition and `fit` it to a dataloader, while\nhandling the boring parts like moving data between devices, updating the weights, \nshowing progress bars and tracking metrics.\n\nHere's an example defining and training an Autoencoder for the MNIST dataset.\nWe selected parts of the code to highlight luz functionality. \nYou can find the full example code [here](https://mlverse.github.io/luz/articles/examples/mnist-autoencoder.html).\n\n```{.r}\nnet \u003c- nn_module(\n  \"Net\",\n  initialize = function() {\n    self$encoder \u003c- nn_sequential(\n      nn_conv2d(1, 6, kernel_size=5),\n      nn_relu(),\n      nn_conv2d(6, 16, kernel_size=5),\n      nn_relu()\n    )\n    self$decoder \u003c- nn_sequential(\n      nn_conv_transpose2d(16, 6, kernel_size = 5),\n      nn_relu(),\n      nn_conv_transpose2d(6, 1, kernel_size = 5),\n      nn_sigmoid()\n    )\n  },\n  forward = function(x) {\n    x %\u003e%\n      self$encoder() %\u003e%\n      self$decoder()\n  }\n)\n```\n\nNow that we have defined the Autoencoder architecture using `torch::nn_module()`, we can fit it using luz:\n\n```{.r}\nfitted \u003c- net %\u003e%\n  setup(\n    loss = nn_mse_loss(),\n    optimizer = optim_adam\n  ) %\u003e%\n  fit(train_dl, epochs = 1, valid_data = test_dl)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlverse%2Fluz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmlverse%2Fluz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmlverse%2Fluz/lists"}