docstr: Construct a DPM-Solver.
  We support both the noise prediction model ("predicting epsilon") and the data prediction model ("predicting x0").
  If `predict_x0` is False, we use the solver for the noise prediction model (DPM-Solver).
  If `predict_x0` is True, we use the solver for the data prediction model (DPM-Solver++).
      In such case, we further support the "dynamic thresholding" in [1] when `thresholding` is True.
      The "dynamic thresholding" can greatly improve the sample quality for pixel-space DPMs with large guidance scales.
  Args:
      model_fn: A noise prediction model function which accepts the continuous-time input (t in [epsilon, T]):
          ``
          def model_fn(x, t_continuous):
              return noise
          ``
      noise_schedule: A noise schedule object, such as NoiseScheduleVP.
      predict_x0: A `bool`. If true, use the data prediction model; else, use the noise prediction model.
      thresholding: A `bool`. Valid when `predict_x0` is True. Whether to use the "dynamic thresholding" in [1].
      max_val: A `float`. Valid when both `predict_x0` and `thresholding` are True. The max value for thresholding.
  
  [1] Chitwan Saharia, William Chan, Saurabh Saxena, Lala Li, Jay Whang, Emily Denton, Seyed Kamyar Seyed Ghasemipour, Burcu Karagol Ayan, S Sara Mahdavi, Rapha Gontijo Lopes, et al. Photorealistic text-to-image diffusion models with deep language understanding. arXiv preprint arXiv:2205.11487, 2022b.
docstr_tok: ["Construct","a","DPM-Solver",".","We","support","both","the","noise","prediction","model","(","``","predicting","epsilon","''",")","and","the","data","prediction","model","(","``","predicting","x0","''",")",".","If","`","predict_x0","`","is","False",",","we","use","the","solver","for","the","noise","prediction","model","(","DPM-Solver",")",".","If","`","predict_x0","`","is","True",",","we","use","the","solver","for","the","data","prediction","model","(","DPM-Solver++",")",".","In","such","case",",","we","further","support","the","``","dynamic","thresholding","''","in","[","1","]","when","`","thresholding","`","is","True",".","The","``","dynamic","thresholding","''","can","greatly","improve","the","sample","quality","for","pixel-space","DPMs","with","large","guidance","scales",".","Args",":","model_fn",":","A","noise","prediction","model","function","which","accepts","the","continuous-time","input","(","t","in","[","epsilon",",","T","]",")",":","``","def","model_fn","(","x",",","t_continuous",")",":","return","noise","``","noise_schedule",":","A","noise","schedule","object",",","such","as","NoiseScheduleVP",".","predict_x0",":","A","`","bool","`",".","If","true",",","use","the","data","prediction","model",";","else",",","use","the","noise","prediction","model",".","thresholding",":","A","`","bool","`",".","Valid","when","`","predict_x0","`","is","True",".","Whether","to","use","the","``","dynamic","thresholding","''","in","[","1","]",".","max_val",":","A","`","float","`",".","Valid","when","both","`","predict_x0","`","and","`","thresholding","`","are","True",".","The","max","value","for","thresholding",".","[","1","]","Chitwan","Saharia",",","William","Chan",",","Saurabh","Saxena",",","Lala","Li",",","Jay","Whang",",","Emily","Denton",",","Seyed","Kamyar","Seyed","Ghasemipour",",","Burcu","Karagol","Ayan",",","S","Sara","Mahdavi",",","Rapha","Gontijo","Lopes",",","et","al",".","Photorealistic","text-to-image","diffusion","models","with","deep","language","understanding",".","arXiv","preprint","arXiv:2205.11487",",","2022b","."]
code: def __init__(
      self,
      model_fn,
      noise_schedule,
      predict_x0=False,
      thresholding=False,
      max_val=1.0,
  ):
      """Construct a DPM-Solver.
      We support both the noise prediction model ("predicting epsilon") and the data prediction model ("predicting x0").
      If `predict_x0` is False, we use the solver for the noise prediction model (DPM-Solver).
      If `predict_x0` is True, we use the solver for the data prediction model (DPM-Solver++).
          In such case, we further support the "dynamic thresholding" in [1] when `thresholding` is True.
          The "dynamic thresholding" can greatly improve the sample quality for pixel-space DPMs with large guidance scales.
      Args:
          model_fn: A noise prediction model function which accepts the continuous-time input (t in [epsilon, T]):
              ``
              def model_fn(x, t_continuous):
                  return noise
              ``
          noise_schedule: A noise schedule object, such as NoiseScheduleVP.
          predict_x0: A `bool`. If true, use the data prediction model; else, use the noise prediction model.
          thresholding: A `bool`. Valid when `predict_x0` is True. Whether to use the "dynamic thresholding" in [1].
          max_val: A `float`. Valid when both `predict_x0` and `thresholding` are True. The max value for thresholding.
  
      [1] Chitwan Saharia, William Chan, Saurabh Saxena, Lala Li, Jay Whang, Emily Denton, Seyed Kamyar Seyed Ghasemipour, Burcu Karagol Ayan, S Sara Mahdavi, Rapha Gontijo Lopes, et al. Photorealistic text-to-image diffusion models with deep language understanding. arXiv preprint arXiv:2205.11487, 2022b.
      """
      self.model = model_fn
      self.noise_schedule = noise_schedule
      self.predict_x0 = predict_x0
      self.thresholding = thresholding
      self.max_val = max_val
  
imports: import torch
  import torch.nn.functional
  import math
  from tqdm import tqdm
label_desc: Use image node_id 1 to create a new DPM_Solver object  with example: obj = DPM_Solver(model_fn, noise_schedule, predict_x0, thresholding, max_val)