Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# Check if the input parameters are provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <date> <number>"
exit 1
fi
date_input="$1"
number="$2"
epoch = 100
for _ in range(epoch):
for i in range(len(X)):
x, y = torch.tensor(X[i]), torch.tensor(Y[i])
y_predict = model(x)
loss_tensor = loss(y_predict, y)
loss_tensor.backward()
loss_value = loss_tensor.data[0]
with torch.no_grad():
%pip install torchviz==0.0.2
# one iteration
x = X[0]
y = Y[0]
y_predicted = model(x)
loss_tensor = loss(y_predicted, y)
loss_value = loss_tensor.data[0]
print(f"x: {x}, actual y: {y}, predicted y: {y}, loss: {loss_value}")
print(f"w: {w.data[0]}, b: {w.data[0]}")
@b0noI
b0noI / loss.py
Last active October 31, 2021 00:24
def loss(y_predict, y_actual):
return torch.pow(y_predict - y_actual, 2)
import torch
torch.manual_seed(2021)
w = torch.rand(1, requires_grad=True, dtype=torch.float64)
b = torch.rand(1, requires_grad=True, dtype=torch.float64)
def model(X):
return X * w + b
import numpy as np
def f(x):
return x * 2 + 1
rng = np.random.default_rng(2021)
X = rng.random(1000)
Y = [f(x) for x in X]
# see list of containers: https://github.com/JetBrains/projector-docker
FROM registry.jetbrains.team/p/prj/containers/projector-idea-c:latest
ENV ORG_JETBRAINS_PROJECTOR_SERVER_PORT="8080"
EXPOSE 8080
export CONTAINER_URI="gcr.io/deeplearning-platform-release/experimental.theia.1-7"
export INSTANCE_NAME=...
export PROJECT_NAME=...
export IMAGE_PROJECT="deeplearning-platform-release"
export IMAGE_FAMILY="theia-container-experimental"
export MACHINE_TYPE=... #"n1-standard-4"
export ZONE=.... #"us-central1-a"
gcloud notebooks instances create "${INSTANCE_NAME}" \
--project="${PROJECT_NAME}" \
--location="${ZONE}" \
export CONTAINER_URI="gcr.io/deeplearning-platform-release/experimental.theia.1-7"
export INSTANCE_NAME=...
export PROJECT_NAME=...
export IMAGE_PROJECT="deeplearning-platform-release"
export IMAGE_FAMILY="theia-container-experimental"
export MACHINE_TYPE=... #"n1-standard-4"
export ZONE=... #"us-central1-a"
gcloud compute instances create "${INSTANCE_NAME}" \
--project="${PROJECT_NAME}" \
--zone="${ZONE}" \
INSTANCE_NAME=$1
gcloud compute ssh "jupyter@${INSTANCE_NAME}" -- "sudo rm -rf /home/jupyter/jupyterlab-gcloud-auth"
gcloud compute ssh "jupyter@${INSTANCE_NAME}" -- "mkdir -p /home/jupyter/jupyterlab-gcloud-auth"
gcloud compute scp --recurse ./* "jupyter@${INSTANCE_NAME}:/home/jupyter/jupyterlab-gcloud-auth"
gcloud compute ssh "jupyter@${INSTANCE_NAME}" -- "pip uninstall -y jupyterlab_gcloud_auth"
gcloud compute ssh "jupyter@${INSTANCE_NAME}" -- "pip install /home/jupyter/jupyterlab-gcloud-auth"
gcloud compute ssh "jupyter@${INSTANCE_NAME}" -- "sudo service jupyter restart"
gcloud compute ssh "jupyter@${INSTANCE_NAME}" -- "cd /home/jupyter/jupyterlab-gcloud-auth && jupyter labextension install"