o >¢‹fã@sDddlZddlmZddlZGdd„dejƒZGdd„dejƒZdS)éNcs*eZdZdZd‡fdd„ Zdd„Z‡ZS) ÚPositionalEmbeddingú2 Taken from https://github.com/NVlabs/edm é'Fcs`tƒ ¡||_||_||_tjd|jdtjd}d||j}d|j|}| d|¡dS)Nré)ÚstartÚendÚdtypeéÚfreqs) ÚsuperÚ__init__Ú num_channelsÚ max_positionsÚendpointÚtorchÚarangeÚfloat32Úregister_buffer)Úselfr rrr ©Ú __class__©úA/home/dufour/Documents/diff_plonk/models/positional_embeddings.pyr s zPositionalEmbedding.__init__cCs4t ||j¡}tj| ¡| ¡gdd}| |j¡S)Nr ©Údim)rÚouterr ÚcatÚcosÚsinÚtor)rÚxÚoutrrrÚforwards zPositionalEmbedding.forward)rF©Ú__name__Ú __module__Ú __qualname__Ú__doc__r r"Ú __classcell__rrrrrs rcs*eZdZdZd‡fdd„ Zdd„Z‡ZS)ÚFourierEmbeddingrécs(tƒ ¡| dt |d¡|¡dS)Nr r)r r rrÚrandn)rr Úscalerrrr "s zFourierEmbedding.__init__cCs<| dtj|j |j¡¡}tj| ¡|  ¡gdd}|S)Nrr r) ÚgerÚnpÚpir rrrrrr)rr rrrr"&szFourierEmbedding.forward)r*r#rrrrr)sr))rÚtorch.nnÚnnÚnumpyr.ÚModulerr)rrrrÚs