This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Any, Optional | |
import hashlib | |
import base64 | |
import json | |
def get_hash_bytes(value: Any, hash_bytes=10, salt=None) -> Optional[bytes]: | |
""" | |
param hash_bytes: how many bytes to hake for the trimmed hash, 10 bytes of data -> 16 symbols string | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script is used to stop Cloud instance in case there's no GPU activity for certain period of time | |
# Feel free to contribute https://gist.github.com/artoby/468a7ccbbbc35f6cc904ed668a189a45 | |
idle_seconds_to_shutdown=3600 | |
threshold=0 | |
check_period=0.1 | |
wait_before_shutdown=10 | |
last_activity=$(date +%s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def symlog_bins(arr, n_bins, zero_eps=0.1, padding=0): | |
""" | |
Splits a data range into log-like bins but with 0 and negative values taken into account. | |
Can be used together with matplotlib 'symlog' axis sacale (i.e. ax.set_xscale('symlog')) | |
Feel free to contribute: https://gist.github.com/artoby/0bcf790cfebed5805fbbb6a9853fe5d5 | |
""" | |
a = min(arr) / (1 + padding) | |
b = max(arr) * (1 + padding) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This code is based on implementation from transformers library https://github.com/huggingface/transformers/blob/5daca95dddf940139d749b1ca42c59ebc5191979/src/transformers/convert_bert_pytorch_checkpoint_to_original_tf.py | |
But this particular code snippet implements conversion of BertForSequenceClassification model which isn't supported by transformers library as of now. | |
A sample tf_bert_config_file json file can be found in this gist https://gist.github.com/artoby/b13d2b9d2d6d7f21e195bdb8542709c6 | |
""" | |
import os | |
import tensorflow as tf | |
from transformers import ( |