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
public class Fibonacci { | |
public static long fib(int n) { | |
if (n <= 1) return n; | |
else return fib(n-1) + fib(n-2); | |
} | |
public static void main(String[] args) { | |
int N = Integer.parseInt(args[0]); | |
for (int i = 1; i <= N; i++) | |
System.out.println(i + ": " + fib(i)); |
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 plotly.graph_objects as go | |
def heat_map(x, y, z): | |
""" | |
Generates an interactive heat map using Plotly. | |
This function creates a heat map visualization with the provided x and y axis labels and z axis values. The colors of the map are set to the 'Viridis' scale. The layout of the plot is configured with titles and axes properties, such as the number of ticks, tick text, and tick font properties. The size of the heat map is automatically adjusted based on the input data. Finally, the heat map is displayed in the output. | |
Args: | |
x (list of str): A list of strings representing the labels on the x-axis (n,). |
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 subprocess | |
def get_gpu_memory(): | |
# source: https://stackoverflow.com/a/59571639 | |
command = "nvidia-smi --query-gpu=memory.free --format=csv" | |
memory_free_info = subprocess.check_output(command.split()).decode('ascii').split('\n')[:-1][1:] | |
memory_free_values = [round(int(x.split()[0]) / 1000) for i, x in enumerate(memory_free_info)] | |
return memory_free_values |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 | |
n_cls = 5 | |
a = torch.rand((1, 3, n_cls)) | |
b = torch.tensor([[0, 1, 2]]) | |
print(a.shape) | |
print(b.shape) | |
# > torch.Size([1, 3, 5]) | |
# > torch.Size([1, 3]) |
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 time | |
# with number of iterations | |
n = 10 | |
pbar = tqdm.tqdm(total=n) | |
for t in range(n): | |
pbar.set_description(f'Your information is chaning {t+1}') | |
# do some computation |
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 | |
i = 0 | |
maxlen = 1024 | |
while True: | |
user_input = input('>> User: ').strip() | |
if user_input.lower() == "q": | |
break | |
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
input_ids = tokenizer('summarize: ' + text.lower(), | |
return_tensors='pt').input_ids.to(model.device) | |
output = model.generate( | |
input_ids, | |
max_length=200, | |
num_beams=8, | |
num_beam_groups=4, # based on this paper, https://arxiv.org/pdf/1610.02424.pdf | |
no_repeat_ngram_size=2 | |
) |
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
name: Sync to Hugging Face space | |
on: | |
push: | |
branches: [main] | |
# to run this workflow manually from the Actions tab | |
workflow_dispatch: | |
jobs: |
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
accelerate launch run_mlm.py \ | |
--dataset_name="wikitext" \ | |
--dataset_config_name="wikitext-2-raw-v1" \ | |
--model_name_or_path="albert-base-v2" \ | |
--output_dir="/path/to/output" \ | |
--max_seq_length=256 \ | |
--per_device_train_batch_size=16 \ | |
--per_device_eval_batch_size=16 \ | |
--line_by_line \ | |
--pad_to_max_length |
NewerOlder