-
Notifications
You must be signed in to change notification settings - Fork 441
[feat] GenRL: add runtime and memory stability helpers #1402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -115,16 +115,22 @@ def sde_step_with_logprob( | |||||||||||||||||
| if deterministic: | ||||||||||||||||||
| prev_sample = sample + dt * model_output | ||||||||||||||||||
|
|
||||||||||||||||||
| log_prob = ( | ||||||||||||||||||
| -( | ||||||||||||||||||
| (prev_sample.detach() - prev_sample_mean) ** 2 | ||||||||||||||||||
| std_scale = std_dev_t * torch.sqrt(-1 * dt) | ||||||||||||||||||
| if torch.all(std_scale == 0): | ||||||||||||||||||
| log_prob = torch.zeros_like(prev_sample) | ||||||||||||||||||
| else: | ||||||||||||||||||
| std_scale = torch.clamp( | ||||||||||||||||||
| std_scale, | ||||||||||||||||||
| min=math.sqrt(torch.finfo(std_scale.dtype).tiny), | ||||||||||||||||||
| ) | ||||||||||||||||||
|
Comment on lines
+122
to
125
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clamping Additionally, extremely small values of It is safer to clamp
Suggested change
|
||||||||||||||||||
| / (2 * ((std_dev_t * torch.sqrt(-1 * dt)) ** 2)) | ||||||||||||||||||
| - torch.log(std_dev_t * torch.sqrt(-1 * dt)) | ||||||||||||||||||
| - torch.log( | ||||||||||||||||||
| torch.sqrt(2 * torch.as_tensor(math.pi)) | ||||||||||||||||||
| log_prob = ( | ||||||||||||||||||
| -((prev_sample.detach() - prev_sample_mean) ** 2) | ||||||||||||||||||
| / (2 * (std_scale**2)) | ||||||||||||||||||
| - torch.log(std_scale) | ||||||||||||||||||
| - torch.log( | ||||||||||||||||||
| torch.sqrt(2 * torch.as_tensor(math.pi)) | ||||||||||||||||||
| ) | ||||||||||||||||||
| ) | ||||||||||||||||||
| ) | ||||||||||||||||||
|
|
||||||||||||||||||
| elif sde_type == "flow_cps": | ||||||||||||||||||
| std_dev_t = sigma_prev * math.sin( | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling
torch.cuda.empty_cache()inside the loop for every sample whenasync_reward_scoringisFalseis highly inefficient.empty_cache()is an expensive operation that forces CUDA synchronization and releases cached memory back to the OS, which can significantly slow down the epoch processing.Instead, you should call
torch.cuda.empty_cache()once before the loop starts (e.g., right after_t_reward_wait = time.perf_counter()) ifnot async_reward_scoring, and remove it from inside the loop.