Skip to content

Instantly share code, notes, and snippets.

@JaeDukSeo
Created May 5, 2019 13:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JaeDukSeo/b470ef4763fd6881b9b2e2a419e629cb to your computer and use it in GitHub Desktop.
Save JaeDukSeo/b470ef4763fd6881b9b2e2a419e629cb to your computer and use it in GitHub Desktop.
filter norm
random_direction1 = get_random_weights(copy_of_the_weights)
random_direction2 = get_random_weights(copy_of_the_weights)
for d1,d2,w in zip(random_direction1,random_direction2,copy_of_the_weights):
w_norm = w.view((w.shape[0],-1)) .norm(dim=(1),keepdim=True)[:,:,None,None]
d_norm1 = d1.view((d1.shape[0],-1)).norm(dim=(1),keepdim=True)[:,:,None,None]
d_norm2 = d2.view((d2.shape[0],-1)).norm(dim=(1),keepdim=True)[:,:,None,None]
d1.data = d1.cuda() * (w_norm/(d_norm1.cuda()+1e-10))
d2.data = d2.cuda() * (w_norm/(d_norm2.cuda()+1e-10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment