Skip to content

Instantly share code, notes, and snippets.

View tchaton's full-sized avatar
👻
Always up for it !

thomas chaton tchaton

👻
Always up for it !
View GitHub Profile
import lightning as L
import torch
import torch.nn.functional as F
from lightning.pytorch.demos import Transformer, WikiText2
from torch.utils.data import DataLoader, random_split
import os
from time import sleep
class LanguageModel(L.LightningModule):
# Copyright The Lightning AI team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@tchaton
tchaton / auto_encoder.py
Created August 10, 2023 11:41
Lightning Script
# main.py
# ! pip install torchvision
import torch, torch.nn as nn, torch.utils.data as data, torchvision as tv, torch.nn.functional as F
import lightning as L
# --------------------------------
# Step 1: Define a LightningModule
# --------------------------------
# A LightningModule (nn.Module subclass) defines a full *system*
# (ie: an LLM, diffusion model, autoencoder, or simple image classifier).
@tchaton
tchaton / auto_encoder_with_time.py
Last active April 29, 2024 05:57
auto_encoder_with_time.py
# Copyright The Lightning AI team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
import os
import tarfile
import torch
import torchvision.transforms.functional as fn
from PIL import Image
from tqdm import tqdm as tq
FOLDER_IN = "/data/imagenet"
FOLDER_OUT = "/data/imagenet-final"
FILENAME = "ILSVRC2012_img_{}.tar"
@tchaton
tchaton / role
Last active February 12, 2023 13:22
use private s3. buckets
This gist describes the steps process to add a private bucket on Lightning AI
# 1. Go on your AWS account and search for IAM
# 2. From the left tab, create a policy on AWS with the following JSON. Replace the bucket with yours.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PermissionForObjectOperations",
"Effect": "Allow",
@tchaton
tchaton / board.js
Created December 17, 2022 12:43
React Tutorial
import React, { useState } from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
function calculateWinner(squares) {
const lines = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
@tchaton
tchaton / Boring Model
Created December 2, 2022 12:09
Boring Model
import os
import torch
from torch.utils.data import DataLoader, Dataset
from pytorch_lightning import LightningModule, Trainer
class RandomDataset(Dataset):
def __init__(self, size, length):
import os.path as ops
from lightning import LightningApp
from lightning_hpo import HPOCloudCompute, Sweep
from lightning_hpo.algorithm.optuna import OptunaAlgorithm
from lightning_hpo.distributions.distributions import Categorical, IntUniform, LogUniform, Uniform
app = LightningApp(
Sweep(
@tchaton
tchaton / boring_model.py
Created July 5, 2022 08:00
Simple PyTorch Lightning Boring Model with DDP
import torch
from pytorch_lightning import LightningModule, Trainer
from torch.utils.data import DataLoader, Dataset
class RandomDataset(Dataset):
def __init__(self, size: int, length: int):
self.len = length
self.data = torch.randn(length, size)