question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

One of the stated design decisions from the readme was to support arbitrary modalities, not just images.

I’m in the process of trying to adapt the code for 1D vectors (not H x W x C images).

this line:

noisy_images = noise_scheduler.training_step(clean_inputs, noise_samples, timesteps)

adapted from train_unconditional.py, takes in a (16, 198) clean_inputs tensor and returns a (16, 1, 16, 198) noisy_images tensor. So, 1D tensors are not working out of the box. I am just curious if I am taking the right approach to get 1D tensors to work or there’s no avoiding custom coding a new DDPMScheduler etc.

EDIT: I got the DDPM training_step function to work with this change:

        if len(original_samples.shape) == 2:
            timesteps = timesteps.unsqueeze(-1)
        else:
            timesteps = timesteps.reshape(batch_size, 1, 1, 1)

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
richardrlcommented, Jun 28, 2022

@anton-l @patrickvonplaten Thanks for your input thus far.

I took the latest commit (as of this moment) and made a minimum reproduction of a 1D MLP model and training.

I had to make an additional modification to pipeline_ddpm.py to support noise samples of the right shape.

bimodal_testt.zip

python3 train_unconditional_gaussian_test.py This runs a test on a bimodal gaussian distribution centered at +33, -33 with low variance

It seems to not capture the -33 mode after an epoch or two. Am running the training overnight to see what happens.

Welcome you guys to try running this to see if there’s anything I did wrong

2reactions
patrickvonplatencommented, Jun 24, 2022

Taking a look at the function as is:

    def training_step(self, original_samples: torch.Tensor, noise: torch.Tensor, timesteps: torch.Tensor):
        if timesteps.dim() != 1:
            raise ValueError("`timesteps` must be a 1D tensor")

        device = original_samples.device
        batch_size = original_samples.shape[0]
        timesteps = timesteps.reshape(batch_size, 1, 1, 1)

        sqrt_alpha_prod = self.alphas_cumprod[timesteps] ** 0.5
        sqrt_one_minus_alpha_prod = (1 - self.alphas_cumprod[timesteps]) ** 0.5
        noisy_samples = sqrt_alpha_prod.to(device) * original_samples + sqrt_one_minus_alpha_prod.to(device) * noise
        return noisy_samples

Note that the input can be both torch and numpy tensors -> this should be changed.

Also there shouldn’t be any .to(device) statements, nor framework and modality spefific .reshape(...) operation.

I’d be in favor of implementing framework specific (one for PT one for TF) functions called

def extract(....) in SchedulerMixin that have if framework == "pt" statements in them. Also note that we shouldn’t assume to know the dimension of the input original_samples

Read more comments on GitHub >

github_iconTop Results From Across the Web

New Chemical Modalities and Strategic Thinking in Early Drug ...
New chemical modalities including RNA therapeutics, protein degraders, cyclopeptides, antibody drug conjugates, and gene therapy have ...
Read more >
Next generation therapeutics - AstraZeneca
In fact, 30% of our early pipeline now consists of new drug modalities including oligonucleotides, mRNA and Anticalin ® proteins.
Read more >
New Modalities for Challenging Targets in Drug Discovery
Generally speaking, new modalities may be seen as a concept to address biological targets in the most effective way, by leveraging the strengths ......
Read more >
Emerging modalities of medicine - USP
Medicine is advancing rapidly, with new technologies and treatment modalities being developed to meet the unique needs of patients. These modalities range ...
Read more >
New therapeutic modalities in drug discovery and development
Moreover, the introduction of new therapeutic modalities, besides the so-called classical Rule of 5 (Ro5) [7] compliant molecules, has had some impact.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found