{"id":13625405,"url":"https://github.com/dakenf/stable-diffusion-nodejs","last_synced_at":"2025-10-26T22:31:11.041Z","repository":{"id":159536862,"uuid":"634701497","full_name":"dakenf/stable-diffusion-nodejs","owner":"dakenf","description":"GPU-accelerated javascript runtime for StableDiffusion. Uses modified ONNX runtime to support CUDA and DirectML.","archived":false,"fork":false,"pushed_at":"2023-10-23T14:07:06.000Z","size":363,"stargazers_count":59,"open_issues_count":0,"forks_count":7,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-10T06:25:55.319Z","etag":null,"topics":["cuda","directml","nodejs","stable-diffusion","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/dakenf.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}},"created_at":"2023-05-01T00:34:54.000Z","updated_at":"2024-11-13T18:17:35.000Z","dependencies_parsed_at":"2023-12-31T03:43:53.388Z","dependency_job_id":"74c988c9-0c8b-4d0f-a373-0c41d71d2fd8","html_url":"https://github.com/dakenf/stable-diffusion-nodejs","commit_stats":{"total_commits":10,"total_committers":1,"mean_commits":10.0,"dds":0.0,"last_synced_commit":"805c980e88d5a7cc59a6ff7b2099ed24c1d09b80"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakenf%2Fstable-diffusion-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakenf%2Fstable-diffusion-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakenf%2Fstable-diffusion-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dakenf%2Fstable-diffusion-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dakenf","download_url":"https://codeload.github.com/dakenf/stable-diffusion-nodejs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238223872,"owners_count":19436728,"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":["cuda","directml","nodejs","stable-diffusion","typescript"],"created_at":"2024-08-01T21:01:55.274Z","updated_at":"2025-10-26T22:31:10.722Z","avatar_url":"https://github.com/dakenf.png","language":"TypeScript","funding_links":[],"categories":["nodejs","typescript"],"sub_categories":[],"readme":"# THIS REPOSITORY IS OBSOLETE, USE https://github.com/dakenf/diffusers.js\n\n# Stable Diffusion for Node.js with GPU acceleration on Cuda or DirectML\n\n## Info\nThis is a pure typescript implementation of SD pipeline that runs ONNX versions of the model with [patched ONNX node runtime](https://github.com/dakenf/onnxruntime-node-gpu)\n\n## Requirements\nWarning: this project requires Node 18\n\n### Windows\nWorks out of the box with DirectML. No additional libraries required\n\nYou can speed up things by installing tfjs-node, but i haven't seen significant performance improvements https://github.com/tensorflow/tfjs/tree/master/tfjs-node\n\ntfjs-node might require installing visual studio build tools and python 2.7 https://community.chocolatey.org/packages/visualstudio2022buildtools\n\n### Linux / WSL2\n1. Install CUDA (tested only on 11-7 but 12 should be supported) https://docs.nvidia.com/cuda/cuda-installation-guide-linux/\n2. Install cuDNN https://developer.nvidia.com/rdp/cudnn-archive\n3. Install onnxruntime-linux-x64-gpu-1.14.1 https://github.com/microsoft/onnxruntime/releases/tag/v1.14.1\n### Mac OS M1\nNo requirements but can run only on CPU which is quite slow (about 0.2s/it for fp32 and 0.1s/it for fp16)\n\n## Usage\n```\nnpm i stable-diffusion-nodejs\n```\n\n### Basic windows with SD 2.1\n```typescript\nimport { PNG } from 'pngjs'\nimport { StableDiffusionPipeline } from 'stable-diffusion-nodejs'\n\nconst pipe = await StableDiffusionPipeline.fromPretrained(\n  'directml', // can be 'cuda' on linux or 'cpu' on mac os\n  'aislamov/stable-diffusion-2-1-base-onnx', // relative path or huggingface repo with onnx model\n)\n\nconst image = await pipe.run(\"A photo of a cat\", undefined, 1, 9, 30)\nconst p = new PNG({ width: 512, height: 512, inputColorType: 2 })\np.data = Buffer.from((await image[0].data()))\np.pack().pipe(fs.createWriteStream('output.png')).on('finish', () =\u003e {\n  console.log('Image saved as output.png');\n})\n```\n\n### Accelerated with tfjs-node SD 2.1\n```typescript\nimport * as tf from \"@tensorflow/tfjs-node\"\nimport { StableDiffusionPipeline } from 'stable-diffusion-nodejs'\n\nconst pipe = await StableDiffusionPipeline.fromPretrained(\n  'directml', // can be 'cuda' on linux or 'cpu' on mac os\n  'aislamov/stable-diffusion-2-1-base-onnx', // relative path or huggingface repo with onnx model\n)\n\nconst image = await pipe.run(\"A photo of a cat\", undefined, 1, 9, 30)\nconst png = await tf.node.encodePng(image[0])\nfs.writeFileSync(\"output.png\", png);\n```\n\n### To run 1.X models you need to pass huggingface hub revision and version number = 1\n```typescript\nimport * as tf from \"@tensorflow/tfjs-node\"\nimport { StableDiffusionPipeline } from 'stable-diffusion-nodejs'\n\nconst pipe = await StableDiffusionPipeline.fromPretrained(\n  'directml', // can be 'cuda' on linux or 'cpu' on mac os\n  'CompVis/stable-diffusion-v1-4',\n  'onnx', // hf hub revision\n  1, // SD version, cannot detect automatically yet\n)\n\nconst image = await pipe.run(\"A photo of a cat\", undefined, 1, 9, 30)\nconst png = await tf.node.encodePng(image[0])\nfs.writeFileSync(\"output.png\", png);\n```\n\n## Command-line usage\nTo test inference run this command. It will download SD2.1 onnx version from huggingface hub\n### Windows\n`npm run txt2img -- --prompt \"an astronaut riding a horse\" --provider directml`\n### Linux\n`npm run txt2img -- --prompt \"an astronaut riding a horse\" --provider cuda`\n\nYou can also use `--provider cpu` on a mac or if you don't have a supported videocard\n\n## Converting other models to ONNX\nYou can use this tool to convert any HF hub model to ONNX https://github.com/Amblyopius/Stable-Diffusion-ONNX-FP16\nUse fp16 for Cuda/DirectML and fp32 for Apple M1 (it runs twice faster but still slow)\n\n## Roadmap\n1. Support different schedulers, like DDIMS and UniPCMultistepScheduler\n2. Support batch size \u003e 1\n3. ControlNet support\n4. Add interop between ONNX backend and tensorflow.js to avoid copying data from and to GPU on each inference step\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdakenf%2Fstable-diffusion-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdakenf%2Fstable-diffusion-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdakenf%2Fstable-diffusion-nodejs/lists"}