Skip to content

Instantly share code, notes, and snippets.

View jph00's full-sized avatar
🦘

Jeremy Howard jph00

🦘
View GitHub Profile
@jph00
jph00 / tfm_ast.py
Last active May 25, 2024 02:15
Function to transform each node of `tree` matching types in `names` by passing them to `func`
import ast
from fastcore.utils import *
from fastcore.utils import _get_class
def tfm_ast(tree:ast.AST, func:callable, *names, **kwargs):
"Transform each node of `tree` by passing it to `func`"
def f(self, node):
res = func(node, **kwargs)
return res if res else node
@jph00
jph00 / flash-prefill.txt
Created May 19, 2024 03:14
Examples of situations where gemini-flash ignores the provided prefill. Switching to pro works fine however.
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=$GOOGLE_API_KEY -H 'Content-Type: application/json' -X POST -d '{ "contents":[ {"role": "user", "parts":[{"text": "Write a story about a magic backpack."}] }, {"role": "model", "parts":[{"text": "There was never"}] } ] }'
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=$GOOGLE_API_KEY -H 'Content-Type: application/json' -X POST -d '{ "contents":[ {"role": "user", "parts":[{"text": "What is your favorite color?"}] }, {"role": "model", "parts":[{"text": "Orange is"}] } ] }'
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=$GOOGLE_API_KEY -H 'Content-Type: application/json' -X POST -d '{ "contents":[ {"role": "user", "parts":[{"text": "List 4 colors."}] }, {"role": "model", "parts":[{"text": "- "}] } ] }'
curl https://generativelanguage.googleapis.com/v1beta/mode
@jph00
jph00 / install.sh
Created January 31, 2024 05:42
Install python GPU basics
conda install cuda -c nvidia/label/cuda-12.1.0
conda install 'pytorch>2.0.1' torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
conda install scipy matplotlib pandas notebook
@jph00
jph00 / qlora.py
Created November 1, 2023 01:40
Manual qlora inference example
import torch, time, os, safetensors
from torch import nn
from peft import get_peft_model, LoraConfig, TaskType
from bitsandbytes.nn import Linear4bit, Linear8bitLt
from transformers import AutoTokenizer, LlamaForCausalLM, AutoConfig, LlamaPreTrainedModel, BitsAndBytesConfig
from transformers.utils import hub, WEIGHTS_INDEX_NAME, SAFE_WEIGHTS_INDEX_NAME
from transformers.integrations.bitsandbytes import replace_with_bnb_linear
@jph00
jph00 / fast_peft.py
Last active October 18, 2023 21:08
Make get_peft_model() fast
from bitsandbytes.nn.modules import Linear8bitLt, Linear4bit
from contextlib import contextmanager
def noop (x=None, *args, **kwargs):
"Do nothing"
return x
@contextmanager
def no_kaiming():
old_iku = init.kaiming_uniform_
import torch
from datasets import load_dataset
import argparse
import os
import math
from itertools import chain
from datetime import timedelta
from torch.utils.data import DataLoader
from accelerate import Accelerator
from accelerate.utils import (DummyOptim, DummyScheduler,
@jph00
jph00 / embodiment.md
Created March 26, 2023 03:48
Bing chat about embodiment and grounding

Bing Chat at 2023-3-26 13:47:19

1

Q: Bing AI

2

Q: Some philosophers and AI researchers have claimed that AI can not be sentient, or be AGI, due to lack of "embodiment" or "grounding". Could you please summarize these claims, and points for and against? Who are the main people on each side of this debate?

@jph00
jph00 / task.py
Created October 5, 2022 02:07
Example of using `prepare_for_task` in Hugging Face Datasets
from datasets.tasks import ImageClassification
t = train.rename_columns({'image':'a', 'label':'b'})
t2 = t.prepare_for_task(ImageClassification(image_column='a', label_column='b'))
t2.features
@jph00
jph00 / pull-all.sh
Last active September 25, 2022 15:42
Update in parallel all repos listed in ~/git/repos, and print status of any that are dirty
#!/usr/bin/env bash
for f in $(<~/git/repos); do
cd ~/git/$f
git pull > /dev/null &
cd - > /dev/null
done
wait < <(jobs -p)
for f in $(<~/git/repos); do
@jph00
jph00 / deploy.yml
Last active September 16, 2022 23:42
Deploy quarto website via gh actions
name: Quarto Publish
on:
workflow_dispatch:
push: { branches: master }
jobs:
build-deploy:
runs-on: ubuntu-latest
permissions: {contents: write}
steps:
- uses: actions/checkout@v2