This file contains hidden or 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 | |
#SBATCH --job-name=pytorch-nccl-test | |
#SBATCH --partition= | |
#SBATCH --account= | |
#SBATCH --qos= | |
#SBATCH --nodes=2 | |
#SBATCH --ntasks-per-node=1 | |
#SBATCH --cpus-per-task=32 | |
#SBATCH --gres=gpu:H100:4 | |
#SBATCH --time 0:05:00 |
This file contains hidden or 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 os | |
import json | |
from argparse import ArgumentParser | |
from glob import glob | |
from tqdm import tqdm | |
import torch | |
from safetensors.torch import load_file, save_file | |
from kernel import weight_dequant |
This file contains hidden or 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
""" | |
OpenAI Python SDK Compatible Schemas. | |
Compatible with v1.86.0. Subject to change. | |
See https://github.com/openai/openai-python for the latest version. | |
""" | |
import pyarrow as pa | |
COMPLETION_SCHEMA = pa.schema([ | |
pa.field('id', pa.string()), |
This file contains hidden or 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 argparse | |
import copy | |
import torch | |
import datasets as hfds | |
import transformers | |
from tqdm.auto import tqdm | |
import wandb |
This file contains hidden or 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 functools import partial | |
import types | |
import torch | |
from typing import List, Optional, Tuple, Union, Dict | |
import transformers | |
from transformers.modeling_outputs import BaseModelOutputWithPast | |
from transformers.utils import logging as hf_logging | |
logger = hf_logging.get_logger(__name__) |
This file contains hidden or 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
def get_simple_gradient_expl(model, images, targets, absolute=False): | |
images.requires_grad = True | |
outputs = model(images) | |
outputs = outputs.gather(1, targets.unsqueeze(1)) | |
grad = torch.autograd.grad(torch.unbind(outputs), images, create_graph=True)[0] # create_graph=True for second order derivative | |
expl = grad.abs() if absolute else grad | |
return expl |
This file contains hidden or 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 torch | |
import torch.optim as optim | |
import torchvision | |
import torchvision.transforms as transforms | |
from pathlib import Path | |
from tqdm.auto import tqdm | |
print(torch.cuda.is_available()) | |
dev = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu") | |
# dev = torch.device("cpu") |
This file contains hidden or 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 sys | |
import os # noqa | |
sys.path.insert(0, ".") # noqa | |
import torch | |
from utils.styled_plot import plt | |
from utils.dataset import load_test_image, preprocess_image, normalize_image, convert_idx_to_label | |
from classifiers.cnn_classifier import ImageNetClassifier | |
from solutions.explainers import plot_attributions, aggregate_attribution, normalize_attribution |
This file contains hidden or 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
model.to(device) | |
model.eval() | |
model.zero_grad() | |
def forward_func(inputs, attention_mask=None): | |
return model(inputs, attention_mask=attention_mask).logits | |
lig = LayerIntegratedGradients(forward_func, model.bert.embeddings) | |
all_input_ids, all_ref_input_ids, all_attributions, all_pred_probs, all_pred_class, all_true_class, all_attr_class, all_attr_score, all_convergence_scores = ([] for i in range(9)) |
This file contains hidden or 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
{ | |
"0": "tench, Tinca tinca", | |
"1": "goldfish, Carassius auratus", | |
"2": "great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias", | |
"3": "tiger shark, Galeocerdo cuvieri", | |
"4": "hammerhead, hammerhead shark", | |
"5": "electric ray, crampfish, numbfish, torpedo", | |
"6": "stingray", | |
"7": "cock", | |
"8": "hen", |
NewerOlder