@@ -7427,29 +7427,29 @@ def plot_dynamic_loss_weighting(args, step: int, model, num_timesteps: int = 100
74277427 :param device: Device to run computations on.
74287428 """
74297429 with torch .inference_mode ():
7430- # Generate a range of timesteps
7431- timesteps = torch .linspace (0 , num_timesteps - 1 , num_timesteps ).to ("cpu" ).long ()
7432-
74337430 model .train (False )
7434- loss , loss_scale = model (torch .ones_like (timesteps , device = device ), timesteps )
7431+ timesteps = torch .arange (0 , 1000 , device = device , dtype = torch .long )
7432+ learnedweights = model ._forward (timesteps ).cpu ().numpy ()
7433+ lambdas = model .lambda_weights .cpu ().numpy ()
7434+ learnedweights = lambdas / np .exp (learnedweights )
74357435 model .train (True )
74367436
74377437 # Plot the dynamic loss weights over time
74387438 plt .figure (figsize = (10 , 6 ))
7439- plt .plot (timesteps .cpu ().numpy (), loss . cpu (). numpy () ,
7439+ plt .plot (timesteps .cpu ().numpy (), learnedweights ,
74407440 label = f'Dynamic Loss Weight\n Step: { step } ' )
74417441 plt .xlabel ('Timesteps' )
74427442 plt .ylabel ('Weight' )
74437443 plt .title ('Dynamic Loss Weighting vs Timesteps' )
74447444 plt .legend ()
74457445 plt .grid (True )
7446- plt .ylim (bottom = 1 )
7446+ plt .ylim (bottom = 0 )
74477447 if args .edm2_loss_weighting_generate_graph_y_limit is not None :
74487448 plt .ylim (top = int (args .edm2_loss_weighting_generate_graph_y_limit ))
74497449 plt .xlim (left = 0 , right = num_timesteps )
74507450 plt .xticks (np .arange (0 , num_timesteps + 1 , 100 ))
74517451 # plt.show()
7452-
7452+
74537453 try :
74547454 os .makedirs (args .edm2_loss_weighting_generate_graph_output_dir , exist_ok = True )
74557455 output_dir = os .path .join (args .edm2_loss_weighting_generate_graph_output_dir , args .output_name )
0 commit comments