Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Python 3.11 to CI tests #91

Merged
merged 18 commits into from
Feb 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into multiprocessing
  • Loading branch information
norabelrose committed Feb 19, 2023
commit 03b782d80ae59bda25debe1cdee88858b677d537
11 changes: 6 additions & 5 deletions elk/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from .files import args_to_uuid
from .list import list_runs
from argparse import ArgumentParser
from contextlib import nullcontext, redirect_stdout
import logging
import os


def run():
"""Run `elk`.
Expand Down Expand Up @@ -45,6 +43,9 @@ def run():
list_runs(args)
return

# Import here and not at the top to speed up `elk list`
from .extraction.extraction_main import run as run_extraction
from .training.train import train
from transformers import AutoConfig, PretrainedConfig

if model := getattr(args, "model", None):
Expand All @@ -62,14 +63,14 @@ def run():
args.layers = list(range(0, num_layers, args.layer_stride))

# Default to CUDA iff available
# TODO: args.device isn't used right now because model needs to be loaded on CPU first
# args.device isn't used right now because model needs to be loaded on CPU first
if args.device is None:
import torch

if not torch.cuda.is_available():
args.device = "cpu"
else:
args.device = f"cuda"
args.device = "cuda"

# Prevent printing from processes other than the first one
for key in list(vars(args).keys()):
Expand Down
2 changes: 1 addition & 1 deletion elk/extraction/extraction_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def extract(args, split: str):
prompt_suffix=args.prompt_suffix,
token_loc=args.token_loc,
use_encoder_states=args.use_encoder_states,
num_procs=torch.cuda.device_count()
num_procs=torch.cuda.device_count(),
)
]
save_dir.mkdir(parents=True, exist_ok=True)
Expand Down
6 changes: 4 additions & 2 deletions elk/extraction/prompt_collator.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ def __len__(self):
return N

def set_labels(self):
self.labels, counts = np.unique(self.dataset[self.label_column], return_counts=True)
self.labels, counts = np.unique(
self.dataset[self.label_column], return_counts=True
)
self.label_fracs = counts / counts.sum()

def split_and_copy(self, indices, new_seed):
Expand All @@ -160,7 +162,7 @@ def split_and_copy(self, indices, new_seed):
according to given indices.
"""
dataset_split = self.dataset.select(indices)

# only shallow copy is needed -- multiprocess will pickle (dill) objects
self_copy = copy.copy(self)
self_copy.dataset = dataset_split
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.