Skip to content

Instantly share code, notes, and snippets.

View jihunchoi's full-sized avatar
🥕

Jihun Choi jihunchoi

🥕
View GitHub Profile
import os
from typing import List, Optional
import boto3
from hydra.core.object_type import ObjectType
from hydra.plugins.config_source import ConfigResult, ConfigSource
from omegaconf import OmegaConf
from smart_open import open, parse_uri
@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)
@jihunchoi
jihunchoi / pycrayon_clean.py
Created March 18, 2017 15:47
Remove all experiments in a PyCrayon server.
"""Clean all experiments in a PyCrayon server."""
from pycrayon import CrayonClient
def main():
client = CrayonClient()
client.remove_all_experiments()
if __name__ == '__main__':