Instructions to use lsmpp/kontextrefiner with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use lsmpp/kontextrefiner with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("lsmpp/kontextrefiner", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
| import gc | |
| import unittest | |
| import torch | |
| from diffusers import ( | |
| StableDiffusionXLPipeline, | |
| ) | |
| from diffusers.utils.testing_utils import ( | |
| backend_empty_cache, | |
| enable_full_determinism, | |
| require_torch_accelerator, | |
| slow, | |
| torch_device, | |
| ) | |
| from .single_file_testing_utils import SDXLSingleFileTesterMixin | |
| enable_full_determinism() | |
| class StableDiffusionXLPipelineSingleFileSlowTests(unittest.TestCase, SDXLSingleFileTesterMixin): | |
| pipeline_class = StableDiffusionXLPipeline | |
| ckpt_path = "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0.safetensors" | |
| repo_id = "stabilityai/stable-diffusion-xl-base-1.0" | |
| original_config = ( | |
| "https://raw.githubusercontent.com/Stability-AI/generative-models/main/configs/inference/sd_xl_base.yaml" | |
| ) | |
| def setUp(self): | |
| super().setUp() | |
| gc.collect() | |
| backend_empty_cache(torch_device) | |
| def tearDown(self): | |
| super().tearDown() | |
| gc.collect() | |
| backend_empty_cache(torch_device) | |
| def get_inputs(self, device, generator_device="cpu", dtype=torch.float32, seed=0): | |
| generator = torch.Generator(device=generator_device).manual_seed(seed) | |
| inputs = { | |
| "prompt": "a fantasy landscape, concept art, high resolution", | |
| "generator": generator, | |
| "num_inference_steps": 2, | |
| "strength": 0.75, | |
| "guidance_scale": 7.5, | |
| "output_type": "np", | |
| } | |
| return inputs | |
| def test_single_file_format_inference_is_same_as_pretrained(self): | |
| super().test_single_file_format_inference_is_same_as_pretrained(expected_max_diff=1e-3) | |