text
stringlengths
1
93.6k
destButton.grid(row=5, column=2)
self.statusLabel = Label(self.top, text='Brought to you by Oh Shunhao and NUSMods')
self.statusLabel.grid(row=6, columnspan=3, padx=20, pady=20)
startButton = Button(self.top, text='Start Download!', command=self.startDownload)
startButton.grid(row=7, columnspan=3)
root.mainloop()
def askForDestination(self):
self.destination = tkFileDialog.askdirectory(mustexist=False, parent=self.top, title='Choose a destination')
self.destField.delete(0, END)
self.destField.insert(0, self.destination)
def startDownload(self):
module = self.moduleField.get()
username = self.usernameField.get()
password = self.passwordField.get()
destination = self.destField.get()
ed = examdownloader.examdownloader('GUI')
def downloadCallback(status, lastfile='', numFiles=0):
if status:
self.updateStatus(str(numFiles) + ' papers downloaded successfully!', 'success')
subprocess.call(['open', '-R', lastfile])
else:
self.updateStatus('Paper not released by Department', 'error')
thread.start_new_thread(ed.getContents, (module, username, password, destination, downloadCallback, self.updateStatus))
def updateStatus(self, msg, type='normal'):
self.statusLabel['text'] = msg
if type == 'success':
self.statusLabel['fg'] = 'green'
elif type == 'error':
self.statusLabel['fg'] = 'red'
else:
self.statusLabel['fg'] = 'blue'
if __name__ == '__main__':
examdownloadergui()
# <FILESEP>
import torch
import numpy as np
from rope import apply_rotary_emb
seed = 0
def construct_query() -> torch.Tensor:
'''
Shape: (batch_size, seqlen, n_local_heads, self.head_dim)
'''
return 2 * torch.ones([1, 2, 2, 4])
def construct_key() -> torch.Tensor:
'''
Shape: (batch_size, seqlen, n_local_kv_heads, self.head_dim)
'''
return 3 * torch.ones([1, 2, 2, 4])
def test_apply_rotary_emb() -> tuple[torch.Tensor, torch.Tensor]:
rng = np.random.default_rng(seed)
torch.manual_seed(seed)
model = torch.nn.Linear(3, 2, bias=False)
test_query = construct_query()
test_key = construct_key()
rotary_embeddings = apply_rotary_emb(test_query, test_key, 4, 20)
rotary_query_embedding, rotary_key_embedding = rotary_embeddings
return rotary_query_embedding, rotary_key_embedding
actual_query_rope_embedding, actual_key_rope_embedding = test_apply_rotary_emb()
ref_query_rope_embedding, ref_key_rope_embedding = torch.load("./rotary_embedding_actual.data")
assert torch.allclose(ref_query_rope_embedding, actual_query_rope_embedding)
assert torch.allclose(ref_key_rope_embedding, actual_key_rope_embedding)
print("Rotary embedding test passed!")
# <FILESEP>
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
"""Train an autoencoder."""
import argparse
import importlib
import importlib.util
import os
import sys
import time
sys.dont_write_bytecode = True
import numpy as np
import torch
import torch.utils.data