Skip to content

Instantly share code, notes, and snippets.

@user202729
user202729 / A-README.md
Last active September 16, 2024 11:34
Footnote in tabular

Resource for answer in https://tex.stackexchange.com/questions/109467/footnote-in-tabular-environment .

Packages to be tested:

@ebeyabraham
ebeyabraham / convert-hf-to-ggml.py
Created July 14, 2023 17:12
Convert huggingface gpt2 model to ggml
# Convert GPT-2 huggingface transformer model to ggml format
#
# Load the model using GPT2Model.
# Iterate over all variables and write them to a binary file.
#
# For each variable, write the following:
# - Number of dimensions (int)
# - Name length (int)
# - Dimensions (int[n_dims])
# - Name (char[name_length])
@rochacbruno
rochacbruno / validate_dataclass.py
Created September 30, 2021 11:13
Validate Dataclass Python
from typing import Union, List
from dataclasses import dataclass
class Validations:
def __post_init__(self):
"""Run validation methods if declared.
The validation method can be a simple check
that raises ValueError or a transformation to
@Guitaricet
Guitaricet / reproducibility.md
Last active August 12, 2024 19:41
Notes on reproducibility in PyTorch

Reproducibility

ML experiments may be very hard to reproduce. You have a lot of hyperparameters, different dataset splits, different ways to preprocess your data, bugs, etc. Ideally, you should log data split (already preprocessed), all hyperparameters (including learning rate scheduling), the initial state of your model and optimizer, random seeds used for initialization, dataset shuffling and all of your code. Your GPU is also should be in deterministic mode (which is not the default mode). For every single model run. This is a very hard task. Different random seed can significantly change your metrics and even GPU-induced randomness can be important. We're not solving all of these problems, but we need to address at least what we can handle.

For every result you report in the paper you need (at least) to:

  1. Track your model and optimizer hyperparameters (including learning rate schedule)
  2. Save final model parameters
  3. Report all of the parameters in the pap
def load_graph(frozen_graph_filename):
with tf.gfile.GFile(frozen_graph_filename, "rb") as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
with tf.Graph().as_default() as graph:
tf.import_graph_def(graph_def)
return graph
restored_graph = load_graph("frozen_graph.pb")
from tensorflow.python.framework.graph_util import convert_variables_to_constants
from tensorflow.python.tools.optimize_for_inference_lib import optimize_for_inference
def freeze_keras_model(model, export_path=None, clear_devices=True):
"""
Freezes the state of a session into a pruned computation graph.
@param model The Keras model to be optimized for inference.
@param clear_devices Remove the device directives from the graph for better portability.
@return The frozen graph definition.
@SuperShinyEyes
SuperShinyEyes / f1_score.py
Created October 15, 2019 10:16
F1 score in PyTorch
def f1_loss(y_true:torch.Tensor, y_pred:torch.Tensor, is_training=False) -> torch.Tensor:
'''Calculate F1 score. Can work with gpu tensors
The original implmentation is written by Michal Haltuf on Kaggle.
Returns
-------
torch.Tensor
`ndim` == 1. 0 <= val <= 1
@papachristoumarios
papachristoumarios / anonymize.sh
Last active February 6, 2024 10:45
Anonymize source code for blind review paper submission with sed
#!/bin/bash
# Anonymization of source code for blind review paper submission
# using sed to replace words with XXX. It also removes the .git
# directory in the anonymized project to avoid exposing any
# sensitive information about the author(s).
#
# Usage: anonymize.sh /path/to/project words_to_anonymize.txt
# words_to_anonymize.txt contains a word in each line
#
@bretton
bretton / inbound-liquidity-ln.md
Last active April 5, 2024 17:38
How to get Inbound Liquidity on the Lightning Network

How to get Inbound Liquidity on the Lightning Network

There are several ways you can find inbound liquidity on LN.

1. Wait

If your node is up 24x7 and you have some outgoing channels, the network will connect to you if you simply wait.

However, it might take a couple of weeks to get a significant amount of incoming liquidity, and ideally you want your outgoing liquidity to match too.

#!/bin/bash
NVIDIA_DRIVER=/tmp/NVIDIA-Linux-x86_64-410.78.run
DRIVER_URL=http://us.download.nvidia.com/XFree86/Linux-x86_64/410.78/NVIDIA-Linux-x86_64-410.78.run
BLACKLIST_FILE=/etc/modprobe.d/blacklist-nvidia-nouveau.conf
if [ ! -f $BLACKLIST_FILE ]; then
echo "Disabling nouveau driver and then rebooting..."
bash -c "echo blacklist nouveau > /etc/modprobe.d/blacklist-nvidia-nouveau.conf"
bash -c "echo options nouveau modeset=0 >> /etc/modprobe.d/blacklist-nvidia-nouveau.conf"