Skip to content

Latest commit

 

History

History
91 lines (82 loc) · 2.13 KB

File metadata and controls

91 lines (82 loc) · 2.13 KB

TensorStack.Python

C# => Python Diffusers Inferface

Supported Diffusers Pipelines

Chroma

  • ChromaPipeline
  • ChromaImg2ImgPipeline

Qwen Image

  • QwenImagePipeline
  • QwenImageImg2ImgPipeline
  • QwenImageEditPipeline

Wan Video

  • WanPipeline
  • WanImageToVideoPipeline

Z-Image

  • ZImagePipeline
  • ZImageImg2ImgPipeline

Python Virtual Environment

The PythonService can be used to download and install Python and create virtual environments

// Virtual Environment Config
var serverConfig = new EnvironmentConfig
{
    Environment = "default-cuda",
    Directory = "PythonRuntime",
    Requirements =
    [
        "--extra-index-url https://download.pytorch.org/whl/cu118",
        "torch==2.7.0+cu118",
        "typing",
        "wheel",
        "transformers",
        "accelerate",
        "diffusers",
        "protobuf",
        "sentencepiece",
        "pillow",
        "ftfy",
        "scipy",
        "peft"
    ]
};

// PythonManager
var pythonService = new PythonManager(serverConfig);

// Create/Load Virtual Environment
await pythonService.CreateEnvironmentAsync(PipelineProgress.ConsoleCallback);

Python Pipelines

Once you have created a virtual environment you can now load a pipeline

// Pipeline Config
var pipelineConfig = new PipelineConfig
{
    Path = "Qwen/Qwen-Image-Edit",
    Pipeline = "QwenImagePipeline",
    ProcessType = ProcessType.ImageEdit,
    DataType = DataType.Bfloat16,
    MemoryMode = MemoryModeType.OffloadCPU
};

// Create Pipeline Proxy
using (var pythonPipeline = new PythonPipeline(pipelineConfig, PipelineProgress.ConsoleCallback))
{
    // Download/Load Model
    await pythonPipeline.LoadAsync();

    // Generate Option
    var options = new PipelineOptions
    {
        Prompt = "Yarn art style",
        Steps = 30,
        Width = 1024,
        Height = 1024,
        GuidanceScale = 4f,
        Scheduler = SchedulerType.FlowMatchEulerDiscrete,
        ImageInput = new ImageInput("Image.png")
    };

    // Generate
    var response = await pythonPipeline.GenerateAsync(options);

    // Save Image
    await response
        .AsImageTensor()
        .SaveAsync("Result.png");
}