Skip to content

Changing StableDiffusion default Text Encoder to a different one. #7749

Answered by tolgacangoz
danielemolino asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Daniele!
This seems to work:

from transformers import AutoModel, AutoTokenizer
from diffusers import StableDiffusionPipeline
#import torch

text_encoder = AutoModel.from_pretrained("StanfordAIMI/RadBERT")#, load_in_8bit=True)
text_tokenizer = AutoTokenizer.from_pretrained("StanfordAIMI/RadBERT")#, load_in_8bit=True)

text_prompts = ["A Chest X-ray of a patient with pneumonia."]

pipeline = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5",
													text_encoder=text_encoder, safety_checker=None,
													#torch_dtype=torch.float16, variant='fp16'
													).to("cuda")
pipeline.tokenizer = text_tokenizer
pipeline.tokenizer.model_max_length = 512

image = 

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@tolgacangoz
Comment options

@s9anus98a
Comment options

@asomoza
Comment options

@s9anus98a
Comment options

@asomoza
Comment options

Answer selected by danielemolino
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants