Utils

Utilities to avoid re-inventing the wheel

Device


source

get_device

 get_device ()

Usage

device = get_device()
print(device)
print(f"Is MPS (Metal Performance Shader) built? {torch.backends.mps.is_built()}")
mps
Is MPS (Metal Performance Shader) built? True

Seeding


source

set_seed

 set_seed (seed:int=42)

Usage

set_seed()
Seed set to 42

Timing


source

time_it

 time_it (func)

Usage

@time_it
def hello(name):
    """Says hello to someone"""
    sleep(0.001)
    return f"Hello {name}!"

print(hello.__name__)  # Prints: "hello"
print(hello.__doc__)   # Prints: "Says hello to someone"
print(hello('sylain'))
hello
Says hello to someone
hello: 0.105 seconds
Hello sylain!