Skip to content

Instantly share code, notes, and snippets.

View Abusagit's full-sized avatar
🎯

Fedor Velikonivtsev Abusagit

🎯
View GitHub Profile
@vladimirtsyupko
vladimirtsyupko / gist:10964772
Created April 17, 2014 08:32
Git force pull to overwrite local files
git fetch --all
git reset --hard origin/master
git pull origin master
@jihunchoi
jihunchoi / masked_cross_entropy.py
Last active January 22, 2024 19:20
PyTorch workaround for masking cross entropy loss
def _sequence_mask(sequence_length, max_len=None):
if max_len is None:
max_len = sequence_length.data.max()
batch_size = sequence_length.size(0)
seq_range = torch.range(0, max_len - 1).long()
seq_range_expand = seq_range.unsqueeze(0).expand(batch_size, max_len)
seq_range_expand = Variable(seq_range_expand)
if sequence_length.is_cuda:
seq_range_expand = seq_range_expand.cuda()
seq_length_expand = (sequence_length.unsqueeze(1)
@f0nzie
f0nzie / normalize_rows.py
Created September 7, 2017 00:30
Normalize rows of a matrix by dividing rows by the normal of the matrix
def normalizeRows(x):
"""
Implement a function that normalizes each row of the matrix x (to have unit length).
Argument:
x -- A numpy matrix of shape (n, m)
Returns:
x -- The normalized (by row) numpy matrix. You are allowed to modify x.
"""
@standaloneSA
standaloneSA / nvidia.md
Last active October 29, 2024 10:40 — forked from meikuam/nvidia.md
Nvidia GPUs sorted by CUDA cores
@sidneyarcidiacono
sidneyarcidiacono / PROTEINS_embedding.py
Created May 17, 2021 20:56
Train/test split with pytorch-geometric
# Now, we need to perform our train/test split.
# We create a seed, and then shuffle our data
torch.manual_seed(12345)
dataset = dataset.shuffle()
# Once it's shuffled, we slice the data to split
train_dataset = dataset[150:-150]
test_dataset = dataset[0:150]
# Take a look at the training versus test graphs
@sidneyarcidiacono
sidneyarcidiacono / PROTEINS_embedding.py
Created May 17, 2021 20:57
Initialize loaders for batching with pytorch-geometric
# Import DataLoader for batching
from torch_geometric.data import DataLoader
# our DataLoader creates diagonal adjacency matrices, and concatenates features
# and target matrices in the node dimension. This allows differing numbers of nodes and edges
# over examples in one batch. (from pytorch geometric docs)
train_loader = DataLoader(train_dataset, batch_size=64, shuffle=True)
test_loader = DataLoader(test_dataset, batch_size=64, shuffle=False)
@sidneyarcidiacono
sidneyarcidiacono / PROTEINS_embedding.py
Created May 17, 2021 20:59
Building our model with pytorch-geometric
# Import everything we need to build our network:
from torch.nn import Linear
import torch.nn.functional as F
from torch_geometric.nn import GCNConv
from torch_geometric.nn import global_mean_pool
# Define our GCN class as a pytorch Module
class GCN(torch.nn.Module):
def __init__(self, hidden_channels):
super(GCN, self).__init__()
@Abusagit
Abusagit / read_vcf.py
Created June 4, 2021 15:46 — forked from dceoy/read_vcf.py
[Python] Read VCF (variant call format) as pandas.DataFrame
#!/usr/bin/env python
import io
import os
import pandas as pd
def read_vcf(path):
with open(path, 'r') as f:
lines = [l for l in f if not l.startswith('##')]
@poedator
poedator / cuda_update.md
Last active November 26, 2023 13:14
Как обновлять куду на серверах ресёрча и не отстрелить себе ногу.

"Но я уже умею ставить дрова видеокарты себе на комп": на машинах с 8x A100 используется хитрая виртуализация GPU, простые способы установить на них nvidia-driver обычно не работают или работают нестабильно.

Часть 1. Подготовка

до установки важно поставить сделать sudo apt update и чтобы update закончился без ошибок. Если видишь ошибки - исправляй ошибки, пока update не завершится успешно.

Проверьте sudo apt list nvidia-driver* nvidia-fabricmanager* nvidia-fabricmanager-dev* libnvidia-nscq* Эта команда должна вывести в списке свежие версии nvidia-driver и nvidia-fabricmanager. Нужная вам версия должна совпадать у driver и fabricmanager хотя бы до первых трёх чисел. Например, эти версии совпадают:

nvidia-driver-530/unknown,now 530.30.02-0ubuntu1 amd64