-
Notifications
You must be signed in to change notification settings - Fork 70
QVAC-18112 doc: content update - SDK - diffusion - add img2img gen #1796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0213970
doc: content update - sdk - completion
BrunoCampana 5f296c9
doc: content new - SDK - runtime lifecycle
BrunoCampana ce14618
doc: update sidebar - add new page - runtime lifecycle
BrunoCampana f81772c
doc: content update - SDK - diffusion - add img2img gen
BrunoCampana c2018fd
doc: replacement for PR 1735 to be closed
BrunoCampana f53ee1b
Merge branch 'main' into docs/completion-v0.10.0
BrunoCampana 2e9ee73
Merge branch 'docs/completion-v0.10.0' into docs/diffusion
BrunoCampana c5b7d87
doc: new code example - SDK - img gen img2img with flux2
BrunoCampana 6350939
doc: fix broken link in completion page
BrunoCampana e03f430
Merge branch 'docs/completion-v0.10.0' into docs/diffusion
BrunoCampana ea33a75
doc: sdk - create new example - img2img with klein
BrunoCampana 555ca76
Merge branch 'main' into docs/diffusion
BrunoCampana 0291ec4
Merge branch 'main' into docs/diffusion
gianni-cor 35e66aa
Merge branch 'main' into docs/diffusion
BrunoCampana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { | ||
| loadModel, | ||
| unloadModel, | ||
| diffusion, | ||
| FLUX_2_KLEIN_4B_Q4_0, | ||
| FLUX_2_KLEIN_4B_VAE, | ||
| QWEN3_4B_Q4_K_M, | ||
| } from "@qvac/sdk"; | ||
| import fs from "fs"; | ||
| import path from "path"; | ||
|
|
||
| // img2img with FLUX.2 [klein] split-layout — uses in-context conditioning ("flux2_flow"). | ||
|
|
||
| const inputPath = process.argv[2]; | ||
| const prompt = process.argv[3] || "oil painting style, vibrant colors"; | ||
| const outputDir = process.argv[4] || "."; | ||
| const diffusionModelSrc = process.argv[5] || FLUX_2_KLEIN_4B_Q4_0; | ||
| const llmModelSrc = process.argv[6] || QWEN3_4B_Q4_K_M; | ||
| const vaeModelSrc = process.argv[7] || FLUX_2_KLEIN_4B_VAE; | ||
|
|
||
| if (!inputPath) { | ||
| console.error("❌ Error: input image path is required"); | ||
| console.error( | ||
| "Usage: bun run bare:example dist/examples/diffusion-flux2-klein-img2img.js <inputImage> [prompt] [outputDir] [diffusionModelSrc] [llmModelSrc] [vaeModelSrc]", | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| try { | ||
| console.log("Loading FLUX.2 [klein] split-layout model..."); | ||
| const modelId = await loadModel({ | ||
| modelSrc: diffusionModelSrc, | ||
| modelType: "diffusion", | ||
| modelConfig: { | ||
| device: "gpu", | ||
| threads: 4, | ||
| llmModelSrc, | ||
| vaeModelSrc, | ||
| prediction: "flux2_flow", | ||
| }, | ||
| onProgress: (p) => console.log(`Loading: ${p.percentage.toFixed(1)}%`), | ||
| }); | ||
| console.log(`Model loaded: ${modelId}`); | ||
|
|
||
| const init_image = new Uint8Array(fs.readFileSync(inputPath)); | ||
| console.log(`\nTransforming "${inputPath}" with prompt: "${prompt}"`); | ||
|
|
||
| const { progressStream, outputs, stats } = diffusion({ | ||
| modelId, | ||
| prompt, | ||
| init_image, | ||
| steps: 20, | ||
| guidance: 3.5, | ||
| cfg_scale: 1, | ||
| seed: -1, | ||
| }); | ||
|
|
||
| for await (const { step, totalSteps } of progressStream) { | ||
| process.stdout.write(`\rStep ${step}/${totalSteps}`); | ||
| } | ||
| console.log(); | ||
|
|
||
| const buffers = await outputs; | ||
| for (let i = 0; i < buffers.length; i++) { | ||
| const outputPath = path.join(outputDir, `flux2_img2img_${i}.png`); | ||
| fs.writeFileSync(outputPath, buffers[i]!); | ||
| console.log(`Saved: ${outputPath}`); | ||
| } | ||
|
|
||
| console.log("\nStats:", await stats); | ||
| await unloadModel({ modelId, clearStorage: false }); | ||
| console.log("Done."); | ||
| process.exit(0); | ||
| } catch (error) { | ||
| console.error("❌ Error:", error); | ||
| process.exit(1); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.