Skip to content

Instantly share code, notes, and snippets.

@tomasruizt
tomasruizt / incremental_csv_saving.py
Created February 27, 2025 08:16
Incremental CSV saving
import os
import pandas as pd
import time
csv = "file.csv"
for i in range(10):
row = pd.DataFrame([{"time": pd.Timestamp.now(), "data": i}])
time.sleep(0.5)
if i == 9:
@tomasruizt
tomasruizt / batching_modifies_logits.py
Last active August 20, 2024 16:13
An example with Llama3, where batching the input prompts modifies the logits that come out.
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
from transformers import set_seed
checkpoint = "meta-llama/Meta-Llama-3-8B-Instruct"
device = "cuda"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForCausalLM.from_pretrained(checkpoint, torch_dtype=torch.bfloat16, device_map="auto").to(device)
model.eval()
import multiprocessing
import time
inputs = ["a", "b", "c", "d"]
def slow_func(x: str) -> str:
print(f"converting {x} to {x + x}...")
time.sleep(1)
return x + x