Skip to content

Sheggle/epoch-V-code-guidelines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

epoch-V-code-guidelines

Rearrange Over Permute

from einops import rearrange
import torch

# Using rearrange from einops
x = torch.randn(32, 64, 64, 3)
# stands for batch, height, width, channels.
# If you work with this a lot, this starts to become a much clearer way of annotating things.
x_rearranged = rearrange(x, 'b h w c -> b c h w')

# Using permute from PyTorch
x_transposed = x.permute(0, 3, 1, 2)

functional over nn.Module

Functional Over Object-Oriented for Activation Functions and loss functions

Activation functions don't have any state, it's nice to indicate that by using the functional approach.

import torch
import torch.nn.functional as F

# Using functional approach
x = torch.randn(10, 10)
x_relu = F.relu(x)

# Using object-oriented approach
relu = torch.nn.ReLU()
x_relu_obj = relu(x)

Avoid Unnecessary Documentation

# Unnecessary documentation
def add(a, b):
    """
    Adds two numbers together.
    
    Parameters:
    a (int): The first number
    b (int): The second number
    
    Returns:
    int: The sum of a and b
    """
    return a + b

# Clean and self-explanatory code without unnecessary docs
def add(a, b):
    return a + b

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published