Skip to content

Instantly share code, notes, and snippets.

View fynnsu's full-sized avatar

Fynn Schmitt-Ulms fynnsu

View GitHub Profile
@fynnsu
fynnsu / create_tinyllama_smoke.py
Last active October 27, 2025 20:55
Create a reduced "LlamaModel" for llm-compressor smoke test purposes
import json
import torch
from tokenizers import Tokenizer
from transformers import (
AutoModelForCausalLM,
AutoTokenizer,
LlamaConfig,
LlamaForCausalLM,
)
@fynnsu
fynnsu / mnist_visualize_merge.py
Created May 21, 2020 18:16
Simple MNIST Neural Network visualize merge
digit = 3 # The class to display average image of
plt.imshow(x_train[np.argmax(y_train, axis=1) == digit].mean(axis=0).reshape(28,28), cmap='gray')
@fynnsu
fynnsu / mnist_visualize.py
Created May 21, 2020 18:15
Simple MNIST Neural Network
index = 18
print(np.argmax(y_train[index]))
plt.imshow(x_train[index].reshape(28,28), cmap='gray')
@fynnsu
fynnsu / mnist_train_setup.py
Created May 21, 2020 18:15
Simple MNIST Neural Network train setup
BATCH_SIZE = 64
EPOCHS = 50
m = len(x_train)
sess = tf.Session()
sess.run(tf.global_variables_initializer())
@fynnsu
fynnsu / mnist_train.py
Created May 21, 2020 18:14
Simple MNIST Neural Network train
for epoch in range(EPOCHS):
for i in range(BATCH_SIZE, m, BATCH_SIZE):
x_batch = x_train[i-BATCH_SIZE:i]
y_batch = y_train[i-BATCH_SIZE:i]
sess.run(step, feed_dict={X:x_batch, labels:y_batch})
if (epoch+1) % 5 == 0:
predictions, test_loss = sess.run([y, loss], feed_dict={X:x_test,
labels:y_test})
accuracy = np.mean(np.argmax(y_test, axis=1) == np.argmax(predictions,
axis=1))
@fynnsu
fynnsu / mnist_setup.py
Created May 21, 2020 18:14
Simple MNIST Neural Network Setup
import tensorflow as tf
from matplotlib import pyplot as plt
import numpy as np
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('MNIST_data', one_hot=True)
@fynnsu
fynnsu / mnist_randomize.py
Created May 21, 2020 18:13
Simple MNIST Neural Network Randomize
# shuffle training data
combined = list(zip(x_train, y_train))
np.random.shuffle(combined)
x_train[:], y_train[:] = zip(*combined)
# shuffle test data
combined = list(zip(x_test, y_test))
np.random.shuffle(combined)
x_test[:], y_test[:] = zip(*combined)
@fynnsu
fynnsu / mnist_print_shape.py
Created May 21, 2020 18:13
Simple MNIST Neural Network Print Shape
print('x_train:', x_train.shape)
print('y_train:', y_train.shape)
print('x_test:', x_test.shape)
print('y_test:', y_test.shape)
@fynnsu
fynnsu / mnist_predict.py
Created May 21, 2020 18:12
Simple MNIST Neural Network Predict
predictions = sess.run(y, feed_dict={X:x_test})
index = 9
print('Prediction: %d, Label: %d' % (np.argmax(predictions[index]),
np.argmax(y_test[index])))
plt.imshow(x_test[index].reshape(28,28), cmap='gray')
@fynnsu
fynnsu / mnist_loss.py
Created May 21, 2020 18:11
Simple MNIST Neural Network Loss
loss = tf.losses.softmax_cross_entropy(onehot_labels=labels, logits=y)
step = tf.train.AdamOptimizer().minimize(loss)