Writing PyTorch style pseudocode

Hi all. In few research papers I have found that pseudocode for an algorithm is written in PyTorch style. Is there any format for writing these PyTorch style pseudocode. If yes, kindly post the related link.

PS: It would be beneficial if you also post some more research papers with PyTorch style pseudocode.

Thank you


can you share some of these papers you mentioned so we can see what the style looks like?

1 Like

\definecolor{commentcolor}{RGB}{110,154,155}   % define comment color
\newcommand{\PyComment}[1]{\ttfamily\textcolor{commentcolor}{\# #1}}  % add a "#" before the input text "#1"
\newcommand{\PyCode}[1]{\ttfamily\textcolor{black}{#1}} % \ttfamily is the code font


    \PyComment{this is a comment} \\
    \PyComment{this is a comment} \\
    \PyComment{} \\
    \PyComment{going to have indentation} \\
    \PyCode{for i in range(N):} \\
    \Indp   % start indent
        \PyComment{your comment} \\
        \PyCode{your code} \PyComment{inline comment} \\ 
    \Indm % end indent, must end with this, else all the below text will be indented
    \PyComment{this is a comment} \\
    \PyCode{your code}
\caption{PyTorch-style pseudocode for your-algo}

I use the above latex code to construct a Pytorch-Style (more to a Python-Style) pseudocode algorithm table.