@@ -428,43 +428,47 @@ def load_and_convert_flux_klein_weights(safetensors_path, params, num_double_lay
428428 first_leaf = jax .tree_util .tree_leaves (params )[0 ]
429429 target_dtype = first_leaf .dtype
430430
431- def cvt (tensor , transpose = False ):
431+ def convert_and_transpose_tensor (tensor , transpose = False ):
432432 if transpose and len (tensor .shape ) == 2 :
433433 tensor = tensor .T
434434 return jnp .array (tensor , dtype = target_dtype )
435435
436436 # Global layers
437- params ["context_embedder" ]["kernel" ] = cvt (pt_state_dict .pop ("context_embedder.weight" ), transpose = True )
438- params ["x_embedder" ]["kernel" ] = cvt (pt_state_dict .pop ("x_embedder.weight" ), transpose = True )
439- params ["double_stream_modulation_img" ]["kernel" ] = cvt (
437+ params ["context_embedder" ]["kernel" ] = convert_and_transpose_tensor (
438+ pt_state_dict .pop ("context_embedder.weight" ), transpose = True
439+ )
440+ params ["x_embedder" ]["kernel" ] = convert_and_transpose_tensor (pt_state_dict .pop ("x_embedder.weight" ), transpose = True )
441+ params ["double_stream_modulation_img" ]["kernel" ] = convert_and_transpose_tensor (
440442 pt_state_dict .pop ("double_stream_modulation_img.linear.weight" ), transpose = True
441443 )
442- params ["double_stream_modulation_txt" ]["kernel" ] = cvt (
444+ params ["double_stream_modulation_txt" ]["kernel" ] = convert_and_transpose_tensor (
443445 pt_state_dict .pop ("double_stream_modulation_txt.linear.weight" ), transpose = True
444446 )
445- params ["single_stream_modulation" ]["kernel" ] = cvt (
447+ params ["single_stream_modulation" ]["kernel" ] = convert_and_transpose_tensor (
446448 pt_state_dict .pop ("single_stream_modulation.linear.weight" ), transpose = True
447449 )
448- params ["proj_out" ]["kernel" ] = cvt (pt_state_dict .pop ("proj_out.weight" ), transpose = True )
450+ params ["proj_out" ]["kernel" ] = convert_and_transpose_tensor (pt_state_dict .pop ("proj_out.weight" ), transpose = True )
449451
450452 # norm_out
451- params ["norm_out" ]["linear" ]["kernel" ] = cvt (pt_state_dict .pop ("norm_out.linear.weight" ), transpose = True )
453+ params ["norm_out" ]["linear" ]["kernel" ] = convert_and_transpose_tensor (
454+ pt_state_dict .pop ("norm_out.linear.weight" ), transpose = True
455+ )
452456
453457 # time_text_embed (Timestep Embedding)
454458 if "time_guidance_embed.timestep_embedder.linear_1.weight" in pt_state_dict :
455- params ["time_text_embed" ]["FlaxTimestepEmbedding_0" ]["linear_1" ]["kernel" ] = cvt (
459+ params ["time_text_embed" ]["FlaxTimestepEmbedding_0" ]["linear_1" ]["kernel" ] = convert_and_transpose_tensor (
456460 pt_state_dict .pop ("time_guidance_embed.timestep_embedder.linear_1.weight" ), transpose = True
457461 )
458462 if "time_guidance_embed.timestep_embedder.linear_1.bias" in pt_state_dict :
459- params ["time_text_embed" ]["FlaxTimestepEmbedding_0" ]["linear_1" ]["bias" ] = cvt (
463+ params ["time_text_embed" ]["FlaxTimestepEmbedding_0" ]["linear_1" ]["bias" ] = convert_and_transpose_tensor (
460464 pt_state_dict .pop ("time_guidance_embed.timestep_embedder.linear_1.bias" )
461465 )
462466 if "time_guidance_embed.timestep_embedder.linear_2.weight" in pt_state_dict :
463- params ["time_text_embed" ]["FlaxTimestepEmbedding_0" ]["linear_2" ]["kernel" ] = cvt (
467+ params ["time_text_embed" ]["FlaxTimestepEmbedding_0" ]["linear_2" ]["kernel" ] = convert_and_transpose_tensor (
464468 pt_state_dict .pop ("time_guidance_embed.timestep_embedder.linear_2.weight" ), transpose = True
465469 )
466470 if "time_guidance_embed.timestep_embedder.linear_2.bias" in pt_state_dict :
467- params ["time_text_embed" ]["FlaxTimestepEmbedding_0" ]["linear_2" ]["bias" ] = cvt (
471+ params ["time_text_embed" ]["FlaxTimestepEmbedding_0" ]["linear_2" ]["bias" ] = convert_and_transpose_tensor (
468472 pt_state_dict .pop ("time_guidance_embed.timestep_embedder.linear_2.bias" )
469473 )
470474
@@ -486,22 +490,34 @@ def cvt(tensor, transpose=False):
486490 jax_db ["attn" ]["e_qkv" ]["kernel" ] = jnp .array (np .concatenate ([add_q , add_k , add_v ], axis = 1 ), dtype = target_dtype )
487491
488492 # Projections out
489- jax_db ["attn" ]["i_proj" ]["kernel" ] = cvt (pt_state_dict .pop (prefix + "attn.to_out.0.weight" ), transpose = True )
490- jax_db ["attn" ]["e_proj" ]["kernel" ] = cvt (pt_state_dict .pop (prefix + "attn.to_add_out.weight" ), transpose = True )
493+ jax_db ["attn" ]["i_proj" ]["kernel" ] = convert_and_transpose_tensor (
494+ pt_state_dict .pop (prefix + "attn.to_out.0.weight" ), transpose = True
495+ )
496+ jax_db ["attn" ]["e_proj" ]["kernel" ] = convert_and_transpose_tensor (
497+ pt_state_dict .pop (prefix + "attn.to_add_out.weight" ), transpose = True
498+ )
491499
492500 # Norm scales
493- jax_db ["attn" ]["query_norm" ]["scale" ] = cvt (pt_state_dict .pop (prefix + "attn.norm_q.weight" ))
494- jax_db ["attn" ]["key_norm" ]["scale" ] = cvt (pt_state_dict .pop (prefix + "attn.norm_k.weight" ))
495- jax_db ["attn" ]["encoder_query_norm" ]["scale" ] = cvt (pt_state_dict .pop (prefix + "attn.norm_added_q.weight" ))
496- jax_db ["attn" ]["encoder_key_norm" ]["scale" ] = cvt (pt_state_dict .pop (prefix + "attn.norm_added_k.weight" ))
501+ jax_db ["attn" ]["query_norm" ]["scale" ] = convert_and_transpose_tensor (pt_state_dict .pop (prefix + "attn.norm_q.weight" ))
502+ jax_db ["attn" ]["key_norm" ]["scale" ] = convert_and_transpose_tensor (pt_state_dict .pop (prefix + "attn.norm_k.weight" ))
503+ jax_db ["attn" ]["encoder_query_norm" ]["scale" ] = convert_and_transpose_tensor (
504+ pt_state_dict .pop (prefix + "attn.norm_added_q.weight" )
505+ )
506+ jax_db ["attn" ]["encoder_key_norm" ]["scale" ] = convert_and_transpose_tensor (
507+ pt_state_dict .pop (prefix + "attn.norm_added_k.weight" )
508+ )
497509
498510 # SwiGLU MLPs
499- jax_db ["ff" ]["linear_in" ]["kernel" ] = cvt (pt_state_dict .pop (prefix + "ff.linear_in.weight" ), transpose = True )
500- jax_db ["ff" ]["linear_out" ]["kernel" ] = cvt (pt_state_dict .pop (prefix + "ff.linear_out.weight" ), transpose = True )
501- jax_db ["ff_context" ]["linear_in" ]["kernel" ] = cvt (
511+ jax_db ["ff" ]["linear_in" ]["kernel" ] = convert_and_transpose_tensor (
512+ pt_state_dict .pop (prefix + "ff.linear_in.weight" ), transpose = True
513+ )
514+ jax_db ["ff" ]["linear_out" ]["kernel" ] = convert_and_transpose_tensor (
515+ pt_state_dict .pop (prefix + "ff.linear_out.weight" ), transpose = True
516+ )
517+ jax_db ["ff_context" ]["linear_in" ]["kernel" ] = convert_and_transpose_tensor (
502518 pt_state_dict .pop (prefix + "ff_context.linear_in.weight" ), transpose = True
503519 )
504- jax_db ["ff_context" ]["linear_out" ]["kernel" ] = cvt (
520+ jax_db ["ff_context" ]["linear_out" ]["kernel" ] = convert_and_transpose_tensor (
505521 pt_state_dict .pop (prefix + "ff_context.linear_out.weight" ), transpose = True
506522 )
507523
@@ -512,12 +528,16 @@ def cvt(tensor, transpose=False):
512528 s_prefix = f"single_transformer_blocks.{ block_idx } ."
513529
514530 # Joint projections
515- jax_sb ["linear1" ]["kernel" ] = cvt (pt_state_dict .pop (s_prefix + "attn.to_qkv_mlp_proj.weight" ), transpose = True )
516- jax_sb ["linear2" ]["kernel" ] = cvt (pt_state_dict .pop (s_prefix + "attn.to_out.weight" ), transpose = True )
531+ jax_sb ["linear1" ]["kernel" ] = convert_and_transpose_tensor (
532+ pt_state_dict .pop (s_prefix + "attn.to_qkv_mlp_proj.weight" ), transpose = True
533+ )
534+ jax_sb ["linear2" ]["kernel" ] = convert_and_transpose_tensor (
535+ pt_state_dict .pop (s_prefix + "attn.to_out.weight" ), transpose = True
536+ )
517537
518538 # Norm scales
519- jax_sb ["attn" ]["query_norm" ]["scale" ] = cvt (pt_state_dict .pop (s_prefix + "attn.norm_q.weight" ))
520- jax_sb ["attn" ]["key_norm" ]["scale" ] = cvt (pt_state_dict .pop (s_prefix + "attn.norm_k.weight" ))
539+ jax_sb ["attn" ]["query_norm" ]["scale" ] = convert_and_transpose_tensor (pt_state_dict .pop (s_prefix + "attn.norm_q.weight" ))
540+ jax_sb ["attn" ]["key_norm" ]["scale" ] = convert_and_transpose_tensor (pt_state_dict .pop (s_prefix + "attn.norm_k.weight" ))
521541
522542 params = jax .tree_util .tree_map (
523543 lambda leaf : jnp .zeros (leaf .shape , dtype = leaf .dtype ) if isinstance (leaf , jax .ShapeDtypeStruct ) else leaf , params
@@ -537,7 +557,7 @@ def load_and_convert_vae_weights(safetensors_path, jax_params):
537557 max_logging .log (f"Loading VAE weights from: { safetensors_path } " )
538558 pt_state_dict = load_file (safetensors_path )
539559
540- def get_w (key ):
560+ def get_pytorch_weight_tensor (key ):
541561 return pt_state_dict [key ]
542562
543563 # Unfreeze JAX params so we can load the weights
@@ -547,45 +567,49 @@ def get_w(key):
547567 max_logging .log ("Mapping VAE decoder weights to JAX parameters..." )
548568
549569 # post_quant_conv
550- jax_params ["post_quant_conv" ]["kernel" ] = jnp .array (get_w ("post_quant_conv.weight" ).transpose (2 , 3 , 1 , 0 ))
551- jax_params ["post_quant_conv" ]["bias" ] = jnp .array (get_w ("post_quant_conv.bias" ))
570+ jax_params ["post_quant_conv" ]["kernel" ] = jnp .array (
571+ get_pytorch_weight_tensor ("post_quant_conv.weight" ).transpose (2 , 3 , 1 , 0 )
572+ )
573+ jax_params ["post_quant_conv" ]["bias" ] = jnp .array (get_pytorch_weight_tensor ("post_quant_conv.bias" ))
552574
553575 # decoder.conv_in
554- jax_params ["decoder" ]["conv_in" ]["kernel" ] = jnp .array (get_w ("decoder.conv_in.weight" ).transpose (2 , 3 , 1 , 0 ))
555- jax_params ["decoder" ]["conv_in" ]["bias" ] = jnp .array (get_w ("decoder.conv_in.bias" ))
576+ jax_params ["decoder" ]["conv_in" ]["kernel" ] = jnp .array (
577+ get_pytorch_weight_tensor ("decoder.conv_in.weight" ).transpose (2 , 3 , 1 , 0 )
578+ )
579+ jax_params ["decoder" ]["conv_in" ]["bias" ] = jnp .array (get_pytorch_weight_tensor ("decoder.conv_in.bias" ))
556580
557581 # decoder.mid_block
558582 # resnets
559583 for idx in [0 , 1 ]:
560584 res_jax = jax_params ["decoder" ]["mid_block" ][f"resnets_{ idx } " ]
561585 res_pt_prefix = f"decoder.mid_block.resnets.{ idx } "
562586
563- res_jax ["norm1" ]["scale" ] = jnp .array (get_w (f"{ res_pt_prefix } .norm1.weight" ))
564- res_jax ["norm1" ]["bias" ] = jnp .array (get_w (f"{ res_pt_prefix } .norm1.bias" ))
565- res_jax ["conv1" ]["kernel" ] = jnp .array (get_w (f"{ res_pt_prefix } .conv1.weight" ).transpose (2 , 3 , 1 , 0 ))
566- res_jax ["conv1" ]["bias" ] = jnp .array (get_w (f"{ res_pt_prefix } .conv1.bias" ))
587+ res_jax ["norm1" ]["scale" ] = jnp .array (get_pytorch_weight_tensor (f"{ res_pt_prefix } .norm1.weight" ))
588+ res_jax ["norm1" ]["bias" ] = jnp .array (get_pytorch_weight_tensor (f"{ res_pt_prefix } .norm1.bias" ))
589+ res_jax ["conv1" ]["kernel" ] = jnp .array (get_pytorch_weight_tensor (f"{ res_pt_prefix } .conv1.weight" ).transpose (2 , 3 , 1 , 0 ))
590+ res_jax ["conv1" ]["bias" ] = jnp .array (get_pytorch_weight_tensor (f"{ res_pt_prefix } .conv1.bias" ))
567591
568- res_jax ["norm2" ]["scale" ] = jnp .array (get_w (f"{ res_pt_prefix } .norm2.weight" ))
569- res_jax ["norm2" ]["bias" ] = jnp .array (get_w (f"{ res_pt_prefix } .norm2.bias" ))
570- res_jax ["conv2" ]["kernel" ] = jnp .array (get_w (f"{ res_pt_prefix } .conv2.weight" ).transpose (2 , 3 , 1 , 0 ))
571- res_jax ["conv2" ]["bias" ] = jnp .array (get_w (f"{ res_pt_prefix } .conv2.bias" ))
592+ res_jax ["norm2" ]["scale" ] = jnp .array (get_pytorch_weight_tensor (f"{ res_pt_prefix } .norm2.weight" ))
593+ res_jax ["norm2" ]["bias" ] = jnp .array (get_pytorch_weight_tensor (f"{ res_pt_prefix } .norm2.bias" ))
594+ res_jax ["conv2" ]["kernel" ] = jnp .array (get_pytorch_weight_tensor (f"{ res_pt_prefix } .conv2.weight" ).transpose (2 , 3 , 1 , 0 ))
595+ res_jax ["conv2" ]["bias" ] = jnp .array (get_pytorch_weight_tensor (f"{ res_pt_prefix } .conv2.bias" ))
572596
573597 # attentions
574598 attn_pt_prefix = "decoder.mid_block.attentions.0"
575599 attn_jax = jax_params ["decoder" ]["mid_block" ]["attentions_0" ]
576600
577- attn_jax ["group_norm" ]["scale" ] = jnp .array (get_w (f"{ attn_pt_prefix } .group_norm.weight" ))
578- attn_jax ["group_norm" ]["bias" ] = jnp .array (get_w (f"{ attn_pt_prefix } .group_norm.bias" ))
601+ attn_jax ["group_norm" ]["scale" ] = jnp .array (get_pytorch_weight_tensor (f"{ attn_pt_prefix } .group_norm.weight" ))
602+ attn_jax ["group_norm" ]["bias" ] = jnp .array (get_pytorch_weight_tensor (f"{ attn_pt_prefix } .group_norm.bias" ))
579603
580- attn_jax ["query" ]["kernel" ] = jnp .array (get_w (f"{ attn_pt_prefix } .to_q.weight" ).T )
581- attn_jax ["query" ]["bias" ] = jnp .array (get_w (f"{ attn_pt_prefix } .to_q.bias" ))
582- attn_jax ["key" ]["kernel" ] = jnp .array (get_w (f"{ attn_pt_prefix } .to_k.weight" ).T )
583- attn_jax ["key" ]["bias" ] = jnp .array (get_w (f"{ attn_pt_prefix } .to_k.bias" ))
584- attn_jax ["value" ]["kernel" ] = jnp .array (get_w (f"{ attn_pt_prefix } .to_v.weight" ).T )
585- attn_jax ["value" ]["bias" ] = jnp .array (get_w (f"{ attn_pt_prefix } .to_v.bias" ))
604+ attn_jax ["query" ]["kernel" ] = jnp .array (get_pytorch_weight_tensor (f"{ attn_pt_prefix } .to_q.weight" ).T )
605+ attn_jax ["query" ]["bias" ] = jnp .array (get_pytorch_weight_tensor (f"{ attn_pt_prefix } .to_q.bias" ))
606+ attn_jax ["key" ]["kernel" ] = jnp .array (get_pytorch_weight_tensor (f"{ attn_pt_prefix } .to_k.weight" ).T )
607+ attn_jax ["key" ]["bias" ] = jnp .array (get_pytorch_weight_tensor (f"{ attn_pt_prefix } .to_k.bias" ))
608+ attn_jax ["value" ]["kernel" ] = jnp .array (get_pytorch_weight_tensor (f"{ attn_pt_prefix } .to_v.weight" ).T )
609+ attn_jax ["value" ]["bias" ] = jnp .array (get_pytorch_weight_tensor (f"{ attn_pt_prefix } .to_v.bias" ))
586610
587- attn_jax ["proj_attn" ]["kernel" ] = jnp .array (get_w (f"{ attn_pt_prefix } .to_out.0.weight" ).T )
588- attn_jax ["proj_attn" ]["bias" ] = jnp .array (get_w (f"{ attn_pt_prefix } .to_out.0.bias" ))
611+ attn_jax ["proj_attn" ]["kernel" ] = jnp .array (get_pytorch_weight_tensor (f"{ attn_pt_prefix } .to_out.0.weight" ).T )
612+ attn_jax ["proj_attn" ]["bias" ] = jnp .array (get_pytorch_weight_tensor (f"{ attn_pt_prefix } .to_out.0.bias" ))
589613
590614 # decoder.up_blocks
591615 for b_idx in range (4 ):
@@ -596,33 +620,37 @@ def get_w(key):
596620 res_jax = up_block_jax [f"resnets_{ r_idx } " ]
597621 res_pt = f"{ up_block_pt } .resnets.{ r_idx } "
598622
599- res_jax ["norm1" ]["scale" ] = jnp .array (get_w (f"{ res_pt } .norm1.weight" ))
600- res_jax ["norm1" ]["bias" ] = jnp .array (get_w (f"{ res_pt } .norm1.bias" ))
601- res_jax ["conv1" ]["kernel" ] = jnp .array (get_w (f"{ res_pt } .conv1.weight" ).transpose (2 , 3 , 1 , 0 ))
602- res_jax ["conv1" ]["bias" ] = jnp .array (get_w (f"{ res_pt } .conv1.bias" ))
623+ res_jax ["norm1" ]["scale" ] = jnp .array (get_pytorch_weight_tensor (f"{ res_pt } .norm1.weight" ))
624+ res_jax ["norm1" ]["bias" ] = jnp .array (get_pytorch_weight_tensor (f"{ res_pt } .norm1.bias" ))
625+ res_jax ["conv1" ]["kernel" ] = jnp .array (get_pytorch_weight_tensor (f"{ res_pt } .conv1.weight" ).transpose (2 , 3 , 1 , 0 ))
626+ res_jax ["conv1" ]["bias" ] = jnp .array (get_pytorch_weight_tensor (f"{ res_pt } .conv1.bias" ))
603627
604- res_jax ["norm2" ]["scale" ] = jnp .array (get_w (f"{ res_pt } .norm2.weight" ))
605- res_jax ["norm2" ]["bias" ] = jnp .array (get_w (f"{ res_pt } .norm2.bias" ))
606- res_jax ["conv2" ]["kernel" ] = jnp .array (get_w (f"{ res_pt } .conv2.weight" ).transpose (2 , 3 , 1 , 0 ))
607- res_jax ["conv2" ]["bias" ] = jnp .array (get_w (f"{ res_pt } .conv2.bias" ))
628+ res_jax ["norm2" ]["scale" ] = jnp .array (get_pytorch_weight_tensor (f"{ res_pt } .norm2.weight" ))
629+ res_jax ["norm2" ]["bias" ] = jnp .array (get_pytorch_weight_tensor (f"{ res_pt } .norm2.bias" ))
630+ res_jax ["conv2" ]["kernel" ] = jnp .array (get_pytorch_weight_tensor (f"{ res_pt } .conv2.weight" ).transpose (2 , 3 , 1 , 0 ))
631+ res_jax ["conv2" ]["bias" ] = jnp .array (get_pytorch_weight_tensor (f"{ res_pt } .conv2.bias" ))
608632
609633 shortcut_key = f"{ res_pt } .conv_shortcut.weight"
610634 if shortcut_key in pt_state_dict :
611- res_jax ["conv_shortcut" ]["kernel" ] = jnp .array (get_w (shortcut_key ).transpose (2 , 3 , 1 , 0 ))
612- res_jax ["conv_shortcut" ]["bias" ] = jnp .array (get_w (f"{ res_pt } .conv_shortcut.bias" ))
635+ res_jax ["conv_shortcut" ]["kernel" ] = jnp .array (get_pytorch_weight_tensor (shortcut_key ).transpose (2 , 3 , 1 , 0 ))
636+ res_jax ["conv_shortcut" ]["bias" ] = jnp .array (get_pytorch_weight_tensor (f"{ res_pt } .conv_shortcut.bias" ))
613637
614638 if b_idx < 3 :
615639 upsampler_jax = up_block_jax ["upsamplers_0" ]
616640 upsampler_pt = f"{ up_block_pt } .upsamplers.0"
617641
618- upsampler_jax ["conv" ]["kernel" ] = jnp .array (get_w (f"{ upsampler_pt } .conv.weight" ).transpose (2 , 3 , 1 , 0 ))
619- upsampler_jax ["conv" ]["bias" ] = jnp .array (get_w (f"{ upsampler_pt } .conv.bias" ))
642+ upsampler_jax ["conv" ]["kernel" ] = jnp .array (
643+ get_pytorch_weight_tensor (f"{ upsampler_pt } .conv.weight" ).transpose (2 , 3 , 1 , 0 )
644+ )
645+ upsampler_jax ["conv" ]["bias" ] = jnp .array (get_pytorch_weight_tensor (f"{ upsampler_pt } .conv.bias" ))
620646
621647 # decoder.conv_norm_out & conv_out
622- jax_params ["decoder" ]["conv_norm_out" ]["scale" ] = jnp .array (get_w ("decoder.conv_norm_out.weight" ))
623- jax_params ["decoder" ]["conv_norm_out" ]["bias" ] = jnp .array (get_w ("decoder.conv_norm_out.bias" ))
624- jax_params ["decoder" ]["conv_out" ]["kernel" ] = jnp .array (get_w ("decoder.conv_out.weight" ).transpose (2 , 3 , 1 , 0 ))
625- jax_params ["decoder" ]["conv_out" ]["bias" ] = jnp .array (get_w ("decoder.conv_out.bias" ))
648+ jax_params ["decoder" ]["conv_norm_out" ]["scale" ] = jnp .array (get_pytorch_weight_tensor ("decoder.conv_norm_out.weight" ))
649+ jax_params ["decoder" ]["conv_norm_out" ]["bias" ] = jnp .array (get_pytorch_weight_tensor ("decoder.conv_norm_out.bias" ))
650+ jax_params ["decoder" ]["conv_out" ]["kernel" ] = jnp .array (
651+ get_pytorch_weight_tensor ("decoder.conv_out.weight" ).transpose (2 , 3 , 1 , 0 )
652+ )
653+ jax_params ["decoder" ]["conv_out" ]["bias" ] = jnp .array (get_pytorch_weight_tensor ("decoder.conv_out.bias" ))
626654
627655 jax_params = jax .tree_util .tree_map (
628656 lambda leaf : jnp .zeros (leaf .shape , dtype = leaf .dtype ) if isinstance (leaf , jax .ShapeDtypeStruct ) else leaf , jax_params
@@ -632,8 +660,8 @@ def get_w(key):
632660
633661 # Extract Batch Normalization running stats
634662 max_logging .log ("Extracting VAE Batch Normalization running stats..." )
635- bn_mean = jnp .array (get_w ("bn.running_mean" )).reshape (1 , - 1 , 1 , 1 )
636- bn_var = jnp .array (get_w ("bn.running_var" )).reshape (1 , - 1 , 1 , 1 )
663+ bn_mean = jnp .array (get_pytorch_weight_tensor ("bn.running_mean" )).reshape (1 , - 1 , 1 , 1 )
664+ bn_var = jnp .array (get_pytorch_weight_tensor ("bn.running_var" )).reshape (1 , - 1 , 1 , 1 )
637665 batch_norm_eps = 0.0001
638666 bn_std = jnp .sqrt (bn_var + batch_norm_eps )
639667
0 commit comments