class_docstr: An enhanced diffusion implementation with DiffWave-specific inference
  
  Arguments
  ---------
  model: nn.Module
      the underlying model
  timesteps: int
      the total number of timesteps
  noise: str|nn.Module
      the type of noise being used
      "gaussian" will produce standard Gaussian noise
  beta_start: float
      the value of the "beta" parameter at the beginning of the process
      (see DiffWave paper)
  beta_end: float
      the value of the "beta" parameter at the end of the process
  show_progress: bool
      whether to show progress during inference
  
  Example
  -------
  >>> from speechbrain.lobes.models.DiffWave import DiffWave
  >>> diffwave = DiffWave(
  ...     input_channels=80,
  ...     residual_layers=30,
  ...     residual_channels=64,
  ...     dilation_cycle_length=10,
  ...     total_steps=50,
  ... )
  >>> from speechbrain.lobes.models.DiffWave import DiffWaveDiffusion
  >>> from speechbrain.nnet.diffusion import GaussianNoise
  >>> diffusion = DiffWaveDiffusion(
  ...     model=diffwave,
  ...     beta_start=0.0001,
  ...     beta_end=0.05,
  ...     timesteps=50,
  ...     noise=GaussianNoise,
  ... )
  >>> input_mel = torch.rand(1, 80, 100)
  >>> output = diffusion.inference(
  ...     unconditional=False,
  ...     scale=256,
  ...     condition=input_mel,
  ...     fast_sampling=True,
  ...     fast_sampling_noise_schedule=[0.0001, 0.001, 0.01, 0.05, 0.2, 0.5],
  ... )
  >>> output.shape
  torch.Size([1, 25600])
class_docstr_tok: ["An","enhanced","diffusion","implementation","with","DiffWave-specific","inference","Arguments","--","--","--","--","-","model",":","nn.Module","the","underlying","model","timesteps",":","int","the","total","number","of","timesteps","noise",":","str|nn.Module","the","type","of","noise","being","used","``","gaussian","''","will","produce","standard","Gaussian","noise","beta_start",":","float","the","value","of","the","``","beta","''","parameter","at","the","beginning","of","the","process","(","see","DiffWave","paper",")","beta_end",":","float","the","value","of","the","``","beta","''","parameter","at","the","end","of","the","process","show_progress",":","bool","whether","to","show","progress","during","inference","Example","--","--","--","-",">",">",">","from","speechbrain.lobes.models.DiffWave","import","DiffWave",">",">",">","diffwave","=","DiffWave","(","...","input_channels=80",",","...","residual_layers=30",",","...","residual_channels=64",",","...","dilation_cycle_length=10",",","...","total_steps=50",",","...",")",">",">",">","from","speechbrain.lobes.models.DiffWave","import","DiffWaveDiffusion",">",">",">","from","speechbrain.nnet.diffusion","import","GaussianNoise",">",">",">","diffusion","=","DiffWaveDiffusion","(","...","model=diffwave",",","...","beta_start=0.0001",",","...","beta_end=0.05",",","...","timesteps=50",",","...","noise=GaussianNoise",",","...",")",">",">",">","input_mel","=","torch.rand","(","1",",","80",",","100",")",">",">",">","output","=","diffusion.inference","(","...","unconditional=False",",","...","scale=256",",","...","condition=input_mel",",","...","fast_sampling=True",",","...","fast_sampling_noise_schedule=","[","0.0001",",","0.001",",","0.01",",","0.05",",","0.2",",","0.5","]",",","...",")",">",">",">","output.shape","torch.Size","(","[","1",",","25600","]",")"]
docstr: Processes the inference for diffwave
  One inference function for all the locally/globally conditional
  generation and unconditional generation tasks
  Arguments
  ---------
  unconditional: bool
      do unconditional generation if True, else do conditional generation
  scale: int
      scale to get the final output wave length
      for conditional genration, the output wave length is scale * condition.shape[-1]
      for example, if the condition is spectrogram (bs, n_mel, time), scale should be hop length
      for unconditional generation, scale should be the desired audio length
  condition: torch.Tensor
      input spectrogram for vocoding or other conditions for other
      conditional generation, should be None for unconditional generation
  fast_sampling: bool
      whether to do fast sampling
  fast_sampling_noise_schedule: list
      the noise schedules used for fast sampling
  device: str|torch.device
      inference device
  Returns
  ---------
  predicted_sample: torch.Tensor
      the predicted audio (bs, 1, t)
docstr_tok: ["Processes","the","inference","for","diffwave","One","inference","function","for","all","the","locally\/globally","conditional","generation","and","unconditional","generation","tasks","Arguments","--","--","--","--","-","unconditional",":","bool","do","unconditional","generation","if","True",",","else","do","conditional","generation","scale",":","int","scale","to","get","the","final","output","wave","length","for","conditional","genration",",","the","output","wave","length","is","scale","*","condition.shape","[","-1","]","for","example",",","if","the","condition","is","spectrogram","(","bs",",","n_mel",",","time",")",",","scale","should","be","hop","length","for","unconditional","generation",",","scale","should","be","the","desired","audio","length","condition",":","torch.Tensor","input","spectrogram","for","vocoding","or","other","conditions","for","other","conditional","generation",",","should","be","None","for","unconditional","generation","fast_sampling",":","bool","whether","to","do","fast","sampling","fast_sampling_noise_schedule",":","list","the","noise","schedules","used","for","fast","sampling","device",":","str|torch.device","inference","device","Returns","--","--","--","--","-","predicted_sample",":","torch.Tensor","the","predicted","audio","(","bs",",","1",",","t",")"]
code: def inference(
      self,
      unconditional,
      scale,
      condition=None,
      fast_sampling=False,
      fast_sampling_noise_schedule=None,
      device=None,
  ):
      """Processes the inference for diffwave
      One inference function for all the locally/globally conditional
      generation and unconditional generation tasks
      Arguments
      ---------
      unconditional: bool
          do unconditional generation if True, else do conditional generation
      scale: int
          scale to get the final output wave length
          for conditional genration, the output wave length is scale * condition.shape[-1]
          for example, if the condition is spectrogram (bs, n_mel, time), scale should be hop length
          for unconditional generation, scale should be the desired audio length
      condition: torch.Tensor
          input spectrogram for vocoding or other conditions for other
          conditional generation, should be None for unconditional generation
      fast_sampling: bool
          whether to do fast sampling
      fast_sampling_noise_schedule: list
          the noise schedules used for fast sampling
      device: str|torch.device
          inference device
      Returns
      ---------
      predicted_sample: torch.Tensor
          the predicted audio (bs, 1, t)
      """
      if device is None:
          device = torch.device("cuda")
      # either condition or uncondition
      if unconditional:
          assert condition is None
      else:
          assert condition is not None
          device = condition.device
  
      # must define fast_sampling_noise_schedule during fast sampling
      if fast_sampling:
          assert fast_sampling_noise_schedule is not None
  
      if fast_sampling and fast_sampling_noise_schedule is not None:
          inference_noise_schedule = fast_sampling_noise_schedule
          inference_alphas = 1 - torch.tensor(inference_noise_schedule)
          inference_alpha_cum = inference_alphas.cumprod(dim=0)
      else:
          inference_noise_schedule = self.betas
          inference_alphas = self.alphas
          inference_alpha_cum = self.alphas_cumprod
  
      inference_steps = []
      for s in range(len(inference_noise_schedule)):
          for t in range(self.timesteps - 1):
              if (
                  self.alphas_cumprod[t + 1]
                  <= inference_alpha_cum[s]
                  <= self.alphas_cumprod[t]
              ):
                  twiddle = (
                      self.alphas_cumprod[t] ** 0.5
                      - inference_alpha_cum[s] ** 0.5
                  ) / (
                      self.alphas_cumprod[t] ** 0.5
                      - self.alphas_cumprod[t + 1] ** 0.5
                  )
                  inference_steps.append(t + twiddle)
                  break
  
      if not unconditional:
          if (
              len(condition.shape) == 2
          ):  # Expand rank 2 tensors by adding a batch dimension.
              condition = condition.unsqueeze(0)
          audio = torch.randn(
              condition.shape[0],
              scale * condition.shape[-1],
              device=device,
          )
      else:
          audio = torch.randn(1, scale, device=device)
      # noise_scale = torch.from_numpy(alpha_cum**0.5).float().unsqueeze(1).to(device)
  
      for n in range(len(inference_alphas) - 1, -1, -1):
          c1 = 1 / inference_alphas[n] ** 0.5
          c2 = (
              inference_noise_schedule[n]
              / (1 - inference_alpha_cum[n]) ** 0.5
          )
          # predict noise
          noise_pred = self.model(
              audio,
              torch.tensor([inference_steps[n]], device=device),
              condition,
          ).squeeze(1)
          # mean
          audio = c1 * (audio - c2 * noise_pred)
          # add variance
          if n > 0:
              noise = torch.randn_like(audio)
              sigma = (
                  (1.0 - inference_alpha_cum[n - 1])
                  / (1.0 - inference_alpha_cum[n])
                  * inference_noise_schedule[n]
              ) ** 0.5
              audio += sigma * noise
          audio = torch.clamp(audio, -1.0, 1.0)
      return audio
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  from speechbrain.nnet.CNN import Conv1d
  from speechbrain.nnet import linear
  from speechbrain.nnet.diffusion import DenoisingDiffusion
  from math import sqrt
  from torchaudio import transforms
label_desc: Use image node_id 2 for calling the DiffWaveDiffusion obj's underlying member method code with example usage: obj.inference(unconditional, scale, condition, fast_sampling, fast_sampling_noise_schedule, device) and returns: audio