Skip to content

Instantly share code, notes, and snippets.

View ma7dev's full-sized avatar
🧘
.

Mazen ma7dev

🧘
.
View GitHub Profile
@scarecrow1123
scarecrow1123 / dist_log.py
Created September 26, 2019 05:29
Example for handling multiprocess logging when using `torch.distributed`
import argparse
import logging
from logging import Filter
from logging.handlers import QueueHandler, QueueListener
import torch
import torch.distributed as dist
import torch.multiprocessing as mp
from torch.multiprocessing import Queue
@vladalive
vladalive / gdrive_download.md
Created May 16, 2019 14:38
Download Google Drive files from linux terminal via wget

Setup:

  1. Add this code to your ~/.bash_aliases file.
function gdrive_download () {
  CONFIRM=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate "https://docs.google.com/uc?export=download&id=$1" -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')
  wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$CONFIRM&id=$1" -O $2
  rm -rf /tmp/cookies.txt
}
@thomwolf
thomwolf / gradient_accumulation.py
Last active November 23, 2024 20:53
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...
@astamicu
astamicu / Remove videos from Youtube Watch Later playlist.md
Last active April 21, 2025 07:10
Script to remove all videos from Youtube Watch Later playlist

UPDATED 22.11.2022

It's been two years since the last update, so here's the updated working script as per the comments below.

Thanks to BryanHaley for this.

setInterval(function () {
    video = document.getElementsByTagName('ytd-playlist-video-renderer')[0];

 video.querySelector('#primary button[aria-label="Action menu"]').click();
@Ashton-W
Ashton-W / Issue.md
Last active March 12, 2025 12:07
GitHub Markdown toggle code block
Click to toggle contents of `code`
CODE!