{"id":17227183,"url":"https://github.com/triple-mu/kolors-tensorrt-libtorch","last_synced_at":"2026-04-07T19:31:13.118Z","repository":{"id":247097807,"uuid":"825020543","full_name":"triple-Mu/Kolors-TensorRT-libtorch","owner":"triple-Mu","description":"Kolors with TensorRT and libtorch","archived":false,"fork":false,"pushed_at":"2024-07-08T15:35:39.000Z","size":49,"stargazers_count":5,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-28T17:48:28.853Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","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/triple-Mu.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}},"created_at":"2024-07-06T14:42:38.000Z","updated_at":"2024-11-30T03:05:06.000Z","dependencies_parsed_at":"2024-07-08T19:12:57.119Z","dependency_job_id":null,"html_url":"https://github.com/triple-Mu/Kolors-TensorRT-libtorch","commit_stats":null,"previous_names":["triple-mu/kolors-tensorrt-libtorch"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/triple-Mu/Kolors-TensorRT-libtorch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triple-Mu%2FKolors-TensorRT-libtorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triple-Mu%2FKolors-TensorRT-libtorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triple-Mu%2FKolors-TensorRT-libtorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triple-Mu%2FKolors-TensorRT-libtorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/triple-Mu","download_url":"https://codeload.github.com/triple-Mu/Kolors-TensorRT-libtorch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/triple-Mu%2FKolors-TensorRT-libtorch/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31526665,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T16:28:08.000Z","status":"ssl_error","status_checked_at":"2026-04-07T16:28:06.951Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-10-15T04:18:26.614Z","updated_at":"2026-04-07T19:31:13.101Z","avatar_url":"https://github.com/triple-Mu.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kolors-TensorRT-libtorch\n\n用`TensorRT`和`libtorch`简单实现了`Kolors`模型的`pipeline`推理。\n\n## 准备\n\n- 安装`TensorRT`, `TensorRT10`的api相较于`TensorRT8`以下版本变化较大, 目前本仓库做了`TensorRT10`的适配, 建议用`TensorRT10`以上的版本。\n- 从[huggingface](`https://huggingface.co/Kwai-Kolors/Kolors/tree/main`)下载模型。\n- 安装`pytorch`, `onnx`等依赖。\n\n## 导出3个onnx模型用于pipeline\n\n修改[export_onnx.py](export_onnx.py)中的路径相关信息。\n执行:\n\n```shell\npython export_onnx.py\n```\n\n你会得到`text_encoder`, `unet`, `vae`三个onnx模型。\n你可以用[onnxsim](`https://github.com/daquexian/onnx-simplifier`)将它们简化。\n[pr-336](https://github.com/daquexian/onnx-simplifier/pull/336)适配了超过2GB的onnx简化报错，可以尝试安装最新的onnxsim。\n\n执行:\n\n```shell\nonnxsim text_encoder.onnx text_encoder-sim.onnx --save-as-external-data\nonnxsim unet.onnx unet-sim.onnx --save-as-external-data\nonnxsim vae.onnx vae-sim.onnx\n```\n\nonnx很大的情况下, 简化的耗时也很长。\n\n## onnx转换到tensorrt\n\n这里我用了trtexec转化, 比较省事。\n目前测试`text_encoder`部分fp16掉点情况比较大，建议回退到fp32。\n\n```shell\ntrtexec --onnx=text_encoder-sim.onnx --saveEngine=text_encoder.plan --noTF32\ntrtexec --onnx=unet-sim.onnx --saveEngine=unet.plan --fp16\ntrtexec --onnx=vae-sim.onnx --saveEngine=vae.plan --fp16\n```\n\ntensorrt转换的过程也很慢。\n\n## 编译安装python包\n\n执行:\n\n```shell\npython setup.py install\n```\n\n包名是: `py_kolors`\n\n## 推理一个文生图\n\n修改[run.py](run.py)中的3个模型路径, 修改推理步数, 默认50比较慢.\n\n执行:\n\n```shell\npython run.py\n```\n\n生成的图片会保存为`tmp.jpg`。\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftriple-mu%2Fkolors-tensorrt-libtorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftriple-mu%2Fkolors-tensorrt-libtorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftriple-mu%2Fkolors-tensorrt-libtorch/lists"}