{"id":15288077,"url":"https://github.com/cstsunfu/dlk","last_synced_at":"2025-09-18T08:51:19.750Z","repository":{"id":57422981,"uuid":"403693536","full_name":"cstsunfu/dlk","owner":"cstsunfu","description":"A PyTorch Based Deep Learning Quick Develop Framework. One-Stop for train/predict/server/demo","archived":false,"fork":false,"pushed_at":"2025-02-04T17:02:45.000Z","size":9873,"stargazers_count":24,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-19T07:06:28.083Z","etag":null,"topics":["adversarial-training","deep-learning","demo","grid-search","image-captioning","image-classification","lightning","ner","nli","pytorch","relation-extraction","streamlit","summary"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cstsunfu.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":"2021-09-06T16:39:59.000Z","updated_at":"2025-06-14T11:41:56.000Z","dependencies_parsed_at":"2024-10-31T14:03:54.804Z","dependency_job_id":"7b2d4d8e-27dc-4573-ab3b-906f662366be","html_url":"https://github.com/cstsunfu/dlk","commit_stats":{"total_commits":248,"total_committers":2,"mean_commits":124.0,"dds":"0.0040322580645161255","last_synced_commit":"72c2f0f82d08657249711c4d8793c0d8b26dfba6"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/cstsunfu/dlk","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cstsunfu%2Fdlk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cstsunfu%2Fdlk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cstsunfu%2Fdlk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cstsunfu%2Fdlk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cstsunfu","download_url":"https://codeload.github.com/cstsunfu/dlk/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cstsunfu%2Fdlk/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266324489,"owners_count":23911226,"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-07-21T11:47:31.412Z","response_time":64,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"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":["adversarial-training","deep-learning","demo","grid-search","image-captioning","image-classification","lightning","ner","nli","pytorch","relation-extraction","streamlit","summary"],"created_at":"2024-09-30T15:44:04.029Z","updated_at":"2025-09-18T08:51:13.980Z","avatar_url":"https://github.com/cstsunfu.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ch2 align=\"center\"\u003e Deep Learning toolKit (dlk)\u003c/h2\u003e\n\u003c/p\u003e\n\n\n\u003ch3 align=\"center\"\u003e\n    \u003cp\u003eDon't Repeat Yourself\u003c/p\u003e\n\u003c/h3\u003e\n\n\u003cdiv style=\"text-align:center\"\u003e\n\u003cspan style=\"width:80%;display:inline-block\"\u003e\n\n![Arch](./pics/arch.png)\n\n\u003c/div\u003e\n\n\u003ch4 align=\"center\"\u003e\n    \u003cp\u003e\n        \u003cb\u003e简体中文\u003c/b\u003e |\n        \u003ca href=\"https://github.com/cstsunfu/dlk/blob/main/README_en.md\"\u003eEnglish\u003c/a\u003e\n    \u003c/p\u003e\n\u003c/h4\u003e\n\n```\ndlk                                  --\n├── adv_method                       -- adversarial training method like free_lb, fgm, etc.\n├── callback                         -- callbacks, like checkpoint, early_stop, etc.\n├── data                             -- data processor part\n│   ├── data_collate                 -- data collate for collate a batch of data from dataset to dataloader\n│   ├── datamodule                   -- the datamodule a.k.a lightning.LightningDataModule\n│   ├── dataset                      -- the dataset inherit the torch.Dataset\n│   ├── postprocessor                -- the tasks postprocessor\n│   ├── processor                    -- the default processor, which scheduler the subprocessors\n│   └── subprocessor                 -- the subprocessors like tokenizer, token2id, etc.\n├── display                          -- the tasks display setting\n├── imodel                           -- the integrated model, which a.k.a the lightning.LightningModule\n├── initmethod                       -- the initmethod, some classic parameter init methods\n├── nn                               -- builtin nn modules\n│   ├── base_module.py               --\n│   ├── layer                        --\n│   │   ├── decoder                  --\n│   │   ├── embedding                --\n│   │   ├── encoder                  --\n│   │   └── token_gen_decoder        --\n│   ├── loss                         --\n│   ├── model                        --\n│   ├── module                       --\n│   └── utils                        --\n├── token_sample                     -- for text generate, different sample strategies\n├── optimizer                        -- optimizers\n├── scheduler                        -- learning rate schedulers\n├── trainer                          -- the trainer, a.k.a lightning.Trainer\n├── utils                            --\n├── preprocess.py                    -- preprocess datas for train|predict|demo|etc.\n├── train.py                         -- train entry\n├── online.py                        --\n├── predict.py                       -- just predict a bunch of data using the pretrained model\n├── server.py                        -- deploy this to server your pretrained model\n├── demo.py                          -- demo main\n└── version.txt                      --\n```\n\n\n* [Install](#install)\n* [Demo](#demo)\n    * [Grid Search](#grid-search)\n    * [Task Demo](#task-demo)\n* [Usage and Feature](#usage-and-feature)\n    * [使用方法](#使用方法)\n    * [模块注册](#模块注册)\n    * [部分内置模块介绍](#部分内置模块介绍)\n        * [callback](#callback)\n        * [虚拟对抗训练](#虚拟对抗训练)\n        * [复杂训练控制](#复杂训练控制)\n        * [文本生成](#文本生成)\n    * [实现你自己的模型](#你自己的模型)\n    * [More Document](#more-document)\n\n\n虽然最近的一年多通用大模型吸引了大部分人的注意力，但是相信很多人已经意识到任务导向的模型在现阶段仍有其不可替代的一面，而且这些模型在处理某些特定任务时具有更好的可靠性和更高的效率，特别是这些模型可以实现一些Agent来与LLM进行配合。\n\n任务导向的模型开发实际上不像LLM一样可以“一招鲜吃遍天”，而是每个任务的模型都需要针对性的开发，而在工作中我们经常需要对深度神经网络模型进行快速实验，搜索最优结构和参数，并将最优模型进行部署，有时还需要做出demo进行验证.\n\n首先是不同任务的开发实际上有很大一部分是重复的，而同一个任务的训练、预测、部署和demo这几个步骤的核心代码也是一致的，但是在实现上都需要一定的的改动，如果每个步骤都独立开发的话，会使得整个过程非常割裂，而这造成的代码冗余对于长期的代码维护是灾难性的。\n\n`DLK`是一个使用`lightning`的`Trainer`，`intc`为`config`管理系统的集模型训练、参数（架构）搜索、模型预测、模型部署和`demo`为一身，对于同一个模型实现这些功能只需要依赖一份代码，大大降低开发和维护成本.\n\n同时`DLK`作为一个通用的训练框架，我们的各种训练技巧和增强方法也可以非常方便的用于不同的模型, 为此`DLK`内置了很多有用的组件。\n\n除了基础组件之外，`DLK`还为主要的任务提供了丰富的示例，更多的示例会慢慢添加进来\n\n### You Can Edit Your DLK Config Like Python Code\n\n基于[intc](https://github.com/cstsunfu/intc) 所提供的强大的Config管理能力, 你可以像编写python代码一样编写你的config文件\n\n\u003cdiv style=\"display:inline-block\"\u003e\n  \u003cimg src=\"./pics/vscode_intc.gif\" alt=\"vscode\" width=\"412px\"\u003e\n  \u003cimg src=\"./pics/nvim_intc.gif\" alt=\"nvim\" width=\"412px\"\u003e\n\u003c/div\u003e\n\n\n### Install\n\n\n```bash\npip install dlk == 0.1.0\n\n# or clone this repo and cd to the project root dir\npip install .\n```\n\n### Demo\n\n下面是一些基于`dlk`开发的示例:\n\nNOTE: 由于我目前只有一台拥有一张`AMD Radeon VII 16G`的GPU和32G内存的个人PC，算力十分有限，因此这里示例的参数很多都还没有优化至SOTA\n\n\n#### Grid Search\n\n`dlk`基于`intc`进行开发，因此同样提供了参数搜索的能力，而`intc`的`_search`并不仅限于数值类型的参数搜索，也可以对整个模块进行搜索，因此`dlk`实际上也具有模块级的架构搜索能力\n\n`./examples/grid_search_exp`里面提供了一个对超参数进行搜索的示例\n\n训练完模型之后执行：\n\n```bash\ntensorboard --logdir ./logs\n```\n\n\u003cdiv style=\"display:inline-block\"\u003e\n  \u003cimg src=\"./pics/grid_search_hp.png\" alt=\"grid search hyperparameters\" width=\"412px\"\u003e\n  \u003cimg src=\"./pics/grid_search_scalar.png\" alt=\"grid search scalar\" width=\"412px\"\u003e\n\u003c/div\u003e\n\n#### Task Demo\n\nDemo 均位于`examples`目录下，训练完模型后执行：\n\n```bash\nstreamlit run ./demo.py\n```\n\n\u003cdiv style=\"display:inline-block\"\u003e\n  \u003cimg src=\"./pics/span_rel.png\" alt=\"span_rel\" width=\"412px\"\u003e\n  \u003cimg src=\"./pics/seq_lab.png\" alt=\"seq_lab\" width=\"412px\"\u003e\n\u003c/div\u003e\n\n\u003cdiv style=\"display:inline-block\"\u003e\n  \u003cimg src=\"./pics/img_cls.png\" alt=\"img_cls\" width=\"412px\"\u003e\n  \u003cimg src=\"./pics/img_cap.png\" alt=\"image caption\" width=\"412px\"\u003e\n\u003c/div\u003e\n\n\n\u003cdiv style=\"display:inline-block\"\u003e\n  \u003cimg src=\"./pics/summary.png\" alt=\"summary\" width=\"412px\"\u003e\n  \u003cimg src=\"./pics/txt_match.png\" alt=\"text match\" width=\"412px\"\u003e\n\u003c/div\u003e\n\n\u003cdiv style=\"display:inline-block\"\u003e\n  \u003cimg src=\"./pics/txt_reg.png\" alt=\"txt_reg\" width=\"412px\"\u003e\n  \u003cimg src=\"./pics/txt_cls.png\" alt=\"text classification\" width=\"412px\"\u003e\n\u003c/div\u003e\n\n### Usage and Feature\n\n#### 使用方法\n\n一般来说一个常见的`dlk`开发任务包含两个pipeline，即数据预处理pipeline和模型推理pipeline. *实际上这两个步骤是可以放到同一个pipeline中的, 当前示例中的大多数任务都需要对预处理数据的复用，因此使用两个pipeline*\n\n数据预处理pipeline对应的内置入口是`dlk.preprocess.Process`，我们需要编写`process.jsonc` config文件来对预处理过程(训练、推理、deploy过程全都复用同一个文件，因此配置文件中有针对不同`stage`的不同设置)进行配置并初始化`Process`, 将数据传入并执行`run`即可按要求输出预处理好的数据\n\n模型训练pipeline对应的内置入口是`dlk.train.Train`, 我们需要编写`fit.jsonc` config文件来对模型训练（推理和deploy过程也同样复用这个文件），使用配置文件初始化`Train`之后执行`run`即可获得训练好的模型。\n\ndemo则只需要导入训练过程中相同的`process.jsonc`和`fit.jsonc`以及训练好的模型（由`checkpoint` callback组件保存）即可\n\n模型部署只需将`dlk.server.Server`实例化，分发到对应的服务器，通过`Server.fit`接受单条或一个batch的数据即可（TODO: 示例）\n\n\n#### 模块注册\n\nDLK依赖两个注册系统，一套是`intc`的`config`注册`cregister`，一套是`dlk`自己的模块注册，注册原则是一致的，都是将一个模块以`module_type`和`module_name`为`key`注册到注册器中，之所以选择两层的命名作为`key`是因为这样更方便区分不同的模块类型\n\n以`dlk.nn.layer.embedding.static` 为例，我们将`StaticEmbeddingConfig` 作为`StaticEmbedding`的`config`以`(\"embedding\", \"static\")`为key注册到`intc`的`cregister`中，以同样的`key`将`StaticEmbedding`注册到`dlk`的模块注册器`register`中。\n\n使用注册器的好处是，我们可以不必关注具体类在哪里实现，只要知道注册的名称就可以直接获取这个类，这使得我们可以非常方便的在任意位置扩展`embedding`的类型，对于我们在自己的项目里面扩展`dlk`非常重要，注册模块对于`intc`也同样重要。在我们已知`StaticEmbedding`的注册名的情况下，获取这个模块的方法非常简单，可以直接`register.get(\"embedding\", \"static\")`即可，而不必关注他的实际存储位置(`cregister`也有同样的功能)\n\n\n#### 部分内置模块介绍\n\n##### callback\n\n`dlk`的`Trainer`是基于`lightning.Trainer`实现的，因此`dlk`同样可以使用`lightning`提供的`callback`, `dlk.callback`中包含一些常用的`callback`\n\n##### 虚拟对抗训练\n\n`Adversarial Training`是一种常见的提升模型效果的技巧，`dlk`内置了一些常用的针对`embedding`的`adv`方法(`dlk.adv_method`)，`./examples/adv_exp`是一个使用示例\n\n##### 复杂训练控制\n\n`dlk`的`dlk.scheduler`模块提供了多种的训练`scheduler`， `dlk.nn.loss`模块中的`multi_loss`同样针对多个`loss`提供了自由控制各种`loss`的能力\n\n##### 文本生成\n\n`dlk`还参考`fairseq`的实现，实现了多种的`token_sample`方法，为文本生成提供非常强大的控制能力\n\n#### 实现你自己的模型\n\n参考`./examples/001_first_example` 实现你自己的模型\n\n看完例子之后。但你可能会有疑问，这似乎并不比我直接实现一个模型简单，甚至有很多概念让我觉得这看起来更复杂。\n是的，如果你只是想训练一个简单的模型，不需要考虑预测、演示等，没错，但是`dlk`提供了一个非常统一的框架，让你只需按照步骤来实现相应的组件，就可以获得一个可用的模型。并且所有的工作都是可重用的，包括你刚刚实现的组件。\n\n而且`dlk`还提供了很多优化方面的工具，让你不是止步于简单模型\n\n记住这个包的原则是Donot Repeat Yourself\n\n\n#### More Document\n\nTODO\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcstsunfu%2Fdlk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcstsunfu%2Fdlk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcstsunfu%2Fdlk/lists"}