Skip to content

Instantly share code, notes, and snippets.

View yashbonde's full-sized avatar
👽
Up there!

Yash Bonde yashbonde

👽
Up there!
View GitHub Profile
@chicobentojr
chicobentojr / _a-recipe-for-training-neural-networks.md
Created May 10, 2019 12:00
"A Recipe for Training Neural Networks" - Andrej Karpathy

A Recipe for Training Neural Networks - Andrej Karpathy

@thomwolf
thomwolf / gradient_accumulation.py
Last active January 16, 2024 02:38
PyTorch gradient accumulation training loop
model.zero_grad() # Reset gradients tensors
for i, (inputs, labels) in enumerate(training_set):
predictions = model(inputs) # Forward pass
loss = loss_function(predictions, labels) # Compute loss function
loss = loss / accumulation_steps # Normalize our loss (if averaged)
loss.backward() # Backward pass
if (i+1) % accumulation_steps == 0: # Wait for several backward steps
optimizer.step() # Now we can do an optimizer step
model.zero_grad() # Reset gradients tensors
if (i+1) % evaluation_steps == 0: # Evaluate the model when we...
@stevekm
stevekm / pyshell.md
Last active March 10, 2024 14:49
Start an interactive Python shell session from within a script

from here: http://stackoverflow.com/questions/5597836/embed-create-an-interactive-python-shell-inside-a-python-program

paste this inside your script for debugging, to start a Python interactive terminal shell session at that point in the script, super useful for debugging since it lets you explore the Python environment and access objects and variables as they are at that point in the script.

import readline # optional, will allow Up/Down/History in the console
import code
vars = globals().copy()
vars.update(locals())
@FND
FND / wsgi_cors.py
Last active December 14, 2022 06:48
CORS-enabled WSGI server (minimal sample)
#!/usr/bin/env python
def handler(environ, start_response):
method = environ["REQUEST_METHOD"]
origin = environ.get("HTTP_ORIGIN")
cookie = environ.get("HTTP_COOKIE", "N/A")
print ""
print method, environ["PATH_INFO"]
print "Origin:", origin
print "Cookie:", cookie