{"id":20599639,"url":"https://github.com/adamdad/rational_kat_cu","last_synced_at":"2025-09-01T05:34:04.639Z","repository":{"id":257694717,"uuid":"834118990","full_name":"Adamdad/rational_kat_cu","owner":"Adamdad","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-04T01:10:28.000Z","size":300,"stargazers_count":61,"open_issues_count":7,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-02T22:43:45.896Z","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/Adamdad.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-07-26T13:08:19.000Z","updated_at":"2025-06-02T14:26:42.000Z","dependencies_parsed_at":"2024-09-18T05:55:01.276Z","dependency_job_id":"78bf1462-66eb-42b5-8bc9-a922731b7df6","html_url":"https://github.com/Adamdad/rational_kat_cu","commit_stats":null,"previous_names":["adamdad/rational_kat_cu"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Adamdad/rational_kat_cu","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adamdad%2Frational_kat_cu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adamdad%2Frational_kat_cu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adamdad%2Frational_kat_cu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adamdad%2Frational_kat_cu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Adamdad","download_url":"https://codeload.github.com/Adamdad/rational_kat_cu/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Adamdad%2Frational_kat_cu/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273077227,"owners_count":25041358,"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-09-01T02:00:09.058Z","response_time":120,"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":"2024-11-16T08:33:38.528Z","updated_at":"2025-09-01T05:34:04.596Z","avatar_url":"https://github.com/Adamdad.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CUDA/Triton Rational Function for Kolmogorov–Arnold Transformer (KAT)\n\nThis CUDA C++ extension facilitates the use of group rational functions in Kolmogorov–Arnold Transformers (KAT). It support the training and inference of https://github.com/Adamdad/kat.\n\n# News\n- [x] 2025.2.1 The `triton` version of GR-KAT has been implemented. Installing and running KAT is now much easier!\n- [x] 2025.2.2 We implement the 2D version of GR-KAN, using `triton`. The input tensor size is now support `[B, C, H, W]`.\n\n# Installation \nTo install the extension, follow these steps:\n```shell\ngit clone https://github.com/Adamdad/rational_kat_cu.git\ncd rational_kat_cu\npip install -e .\n```\n\n# Usage\nIncorporate the module into your neural network models as shown in the example below, which uses the rational function as an activation layer in a simple two-layer KAN architecture.\n```python\nfrom kat_rational import KAT_Group\nclass KAN(nn.Module):\n    \"\"\"MLP as used in Vision Transformer, MLP-Mixer and related networks.\"\"\"\n\n    def __init__(\n            self,\n            in_features,\n            hidden_features=None,\n            out_features=None,\n            act_cfg=dict(type=\"KAT\", act_init=[\"identity\", \"gelu\"]),\n            bias=True,\n            drop=0.,\n    ):\n        super().__init__()\n        out_features = out_features or in_features\n        hidden_features = hidden_features or in_features\n\n        self.fc1 = nn.Linear(in_features, hidden_features, bias=bias)\n        self.act1 = KAT_Group(mode = act_cfg['act_init'][0])\n        self.drop1 = nn.Dropout(drop)\n        self.act2 = KAT_Group(mode = act_cfg['act_init'][1])\n        self.fc2 = nn.Linear(hidden_features, out_features, bias=bias)\n        self.drop2 = nn.Dropout(drop)\n\n    def forward(self, x):\n        x = self.act1(x)\n        x = self.drop1(x)\n        x = self.fc1(x)\n        x = self.act2(x)\n        x = self.drop2(x)\n        x = self.fc2(x)\n        return x\n```\n\nNote: \n1. For `[B, L, C]` and `[B, C]` input, please use `KAT_Group` class, which support tensors where channels comes in the end.\n2. For `[B, C, H, W]` input, please use `KAT_Group2D`. \n\nPPS: I'm not a CUDA expert 😅. If you run into any issues or have suggestions for the code, please feel free to reach out or submit a pull request! 🚀\n\n# Add new function \n\nTo add new functions to the module:\n1. Open `kat_rational/fit.py`.\n2. Implement your custom function within this file.\n3. Add your function to `fit_and_plot_activation` to evaluate and visualize its performance.\n\n# Example\n- Run GR-KAN on MNIST\n```shell\npython example/mnist.py\n```\nResults\n```shell\n# Baseline (GELU Activation)\nGELU - Epoch 1: Loss 0.4548 | Epoch 10: Loss 0.0623\nTraining Time: 84.52 seconds | Test Accuracy: 97.46%\n\n# Optimized (KAT 1DGroup Rational Activation)\nKAT 1DGroup - Epoch 1: Loss 0.3401 | Epoch 10: Loss 0.0245\nTraining Time: 89.11 seconds | Test Accuracy: 97.53%\n```\n\n- Run GR-KAN-2D on CIFAR10\n```shell\npython example/cifar10.py\n```\nResults\n```shell\nReLU Training completed in 136.78 seconds.\nReLU Testing Accuracy: 76.60%, Total time: 138.47 seconds.\n\nKAT 2DGroup Training completed in 416.74 seconds.\nKAT 2DGroup Testing Accuracy: 80.08%, Total time: 418.46 seconds.\n```\n\n# Acknowlegement\n\nWe extend our gratitude to the [rational_activations](https://github.com/ml-research/rational_activations) project for providing the foundational CUDA implementation of rational functions.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamdad%2Frational_kat_cu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadamdad%2Frational_kat_cu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadamdad%2Frational_kat_cu/lists"}