Message Boards Message Boards

Issue with Stable Diffusion V1 net model on Apple Silicon

Posted 1 month ago

I am new to Machine Learning and I would like to experiment with diffusion models. Since Mathematica offers the "Stable Diffusion V1" model, I tried to follow the guide provided here.

My environment is a MacBook Air M1, with only 8GB of unified memory, and I am using version: 14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)

While running the command that will generate an image based on the prompt, I get the following error (picture with the error also attached):

prompt = 
  "funny photo of a cute fluffy cat enjoying a morning croissant and \
drinking coffee in a balcony with breathtaking view, 3d render, \
cinematic, hyperdetailed, cartoon, animation, pixar disney render";
img = netEvaluate[<|"Prompt" -> prompt|>]

During evaluation of In[114]:= NetGraph::netmem1: Insufficient memory to evaluate the network: at least 3.45 gigabytes are required but only 1.28 gigabytes are available for TargetDevice -> CPU. Try to set the BatchSize option to a value smaller than the current value of 32.

Out[115]= Failure["ConfirmationFailed", <|
 "MessageTemplate" -> "`` encountered.", 
  "MessageParameters" :> {$Failed}, "ConfirmationType" -> "Confirm", 
  "Expression" :> $Failed, "Information" -> Null|>]

I've been unlucky in trying to see where I can actually decrease the batch size manually by investigating the options for iNetEvaluate, i.e., this one: Options[iNetEvaluate ] = { TargetDevice -> "CPU", MaxIterations -> 51, RandomSeeding -> Automatic, "SnapshotRatio" -> 1 };

and add BatchSize->16 myself, but it still gives me the same error, which means that the actual batch size is unchanged.

Q: How can I adjust the batch size here, to be able to finally generate my image? Thanks in advance


POSTED BY: Robert Poenaru

Hi Robert,
The batch size in netEvaluate is actually 1, so there is no way to decrease it and in case you want to get the batch of outputs you would have to map netEvaluate on a list of prompts. Do you get those errors from a fresh kernel?

Try to use the ResourceFunction["StableDiffusionSynthesize"], it has similar options. Here are some examples:

  1. Generating a single image: ResourceFunction["StableDiffusionSynthesize"]["A cat in party hat"]
  2. Generating five images based on a single prompt: ResourceFunction["StableDiffusionSynthesize"]["A cat in party hat", 5]
POSTED BY: Maria Sargsyan
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract