https://tutorials.ubuntu.com/tutorial/tutorial-create-a-usb-stick-on-ubuntu#0
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 tqdm | |
| import numpy as np | |
| import torch | |
| import torch.distributed as dist | |
| import transformers | |
| def extract_xml_answer(text: str) -> str: | |
| answer = text.split("<final_answer>")[-1] | |
| answer = answer.split("</final_answer>")[0] | |
| return answer.strip() |
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
| # This implementation is based on the paper: https://github.com/deepseek-ai/DeepSeek-R1/blob/main/DeepSeek_R1.pdf | |
| # | |
| # pip install torch transformers | |
| # python grpo_demo.py | |
| import torch | |
| import torch.nn as nn | |
| import torch.optim as optim | |
| from transformers import BertTokenizer, BertModel |
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 tensorflow as tf | |
| # credit: https://stackoverflow.com/a/66524901/9215780 | |
| class CustomTrainStep(tf.keras.Model): | |
| def __init__(self, n_gradients, *args, **kwargs): | |
| super().__init__(*args, **kwargs) | |
| self.n_gradients = tf.constant(n_gradients, dtype=tf.int32) | |
| self.n_acum_step = tf.Variable(0, dtype=tf.int32, trainable=False) | |
| self.gradient_accumulation = [tf.Variable(tf.zeros_like(v, dtype=tf.float32), | |
| trainable=False) for v in self.trainable_variables] |
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
| # Keras layer implementation of "Fix your classifier: the marginal value of training the last weight layer" | |
| # by Andres Torrubia, licensed under GPL 3: https://www.gnu.org/licenses/gpl-3.0.en.html | |
| # https://arxiv.org/abs/1801.04540 | |
| from keras import backend as K | |
| from keras.engine.topology import Layer | |
| from keras import activations | |
| from keras.initializers import Constant, RandomUniform | |
| import numpy as np | |
| from scipy.linalg import hadamard |
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
| # Info on how to get your api key (kaggle.json) here: https://github.com/Kaggle/kaggle-api#api-credentials | |
| !pip install kaggle | |
| api_token = {"username":"USERNAME","key":"API_KEY"} | |
| import json | |
| import zipfile | |
| import os | |
| with open('/content/.kaggle/kaggle.json', 'w') as file: | |
| json.dump(api_token, file) | |
| !chmod 600 /content/.kaggle/kaggle.json | |
| !kaggle config path -p /content |
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 keras import layers | |
| from keras import models | |
| import tensorflow as tf | |
| # | |
| # generator input params | |
| # | |
| rand_dim = (1, 1, 2048) # dimension of the generator's input tensor (gaussian noise) |