Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed May 3, 2023
1 parent 6d9e9ea commit d108680
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ gpus per model.

This is an example to run a single 8bit llama-65b model on 2 A40s that have
~50 GB of memory each.

```
elk elicit huggyllama/llama-65b imdb --num_gpus 2 --gpus_per_model 2 --int8
```
Expand Down
6 changes: 1 addition & 5 deletions elk/extraction/extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ def extract_hiddens(
world_size: int = 1,
) -> Iterable[dict]:
first_device = (
devices
if not isinstance(devices, ModelDevices)
else devices.first_device
devices if not isinstance(devices, ModelDevices) else devices.first_device
)
"""Run inference on a model with a set of prompts, yielding the hidden states."""
os.environ["TOKENIZERS_PARALLELISM"] = "false"
Expand All @@ -174,15 +172,13 @@ def extract_hiddens(
ds_names = cfg.datasets
assert len(ds_names) == 1, "Can only extract hiddens from one dataset at a time."


model = instantiate_model_with_devices(
cfg=cfg, device_config=devices, is_verbose=is_verbose
)
tokenizer = instantiate_tokenizer(
cfg.model, truncation_side="left", verbose=is_verbose
)


is_enc_dec = model.config.is_encoder_decoder
if is_enc_dec and cfg.use_encoder_states:
assert hasattr(model, "get_encoder") and callable(model.get_encoder)
Expand Down
1 change: 0 additions & 1 deletion elk/utils/multi_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import torch
from accelerate import infer_auto_device_map, init_empty_weights
from torch import dtype
from torch.nn import Module
from transformers import PreTrainedModel

Expand Down
4 changes: 2 additions & 2 deletions tests/test_smoke_elicit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def test_smoke_elicit_run_tiny_gpt2_ccs(tmp_path: Path):
# we need about 5 mb of gpu memory to run this test
model_path, min_mem = "sshleifer/tiny-gpt2", 10 * 1024 ** 2
model_path, min_mem = "sshleifer/tiny-gpt2", 10 * 1024**2
dataset_name = "imdb"
elicit = Elicit(
data=Extract(
Expand Down Expand Up @@ -38,7 +38,7 @@ def test_smoke_elicit_run_tiny_gpt2_ccs(tmp_path: Path):

def test_smoke_elicit_run_tiny_gpt2_eigen(tmp_path: Path):
# we need about 5 mb of gpu memory to run this test
model_path, min_mem = "sshleifer/tiny-gpt2", 10 * 1024 ** 2
model_path, min_mem = "sshleifer/tiny-gpt2", 10 * 1024**2
dataset_name = "imdb"
elicit = Elicit(
data=Extract(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_smoke_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setup_elicit(
tmp_path: Path,
dataset_name="imdb",
model_path="sshleifer/tiny-gpt2",
min_mem=10 * 1024 ** 2,
min_mem=10 * 1024**2,
is_ccs: bool = True,
) -> Elicit:
"""Setup elicit config for testing, execute elicit, and save output to tmp_path.
Expand Down
39 changes: 15 additions & 24 deletions tests/test_split_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,30 @@ def test_split_2_devices_1_gpu_per_model():
devices = ["a", "b"]
gpus_per_model = 1
models_to_create = 2
assert (
split_devices_into_model_devices(
devices=devices,
gpus_per_model=gpus_per_model,
models_to_create=models_to_create,
)
== [ModelDevices("a", []), ModelDevices("b", [])]
)
assert split_devices_into_model_devices(
devices=devices,
gpus_per_model=gpus_per_model,
models_to_create=models_to_create,
) == [ModelDevices("a", []), ModelDevices("b", [])]


def test_split_4_devices_2_gpus_per_model():
devices = ["a", "b", "c", "d"]
gpus_per_model = 2
models_to_create = 2
assert (
split_devices_into_model_devices(
devices=devices,
gpus_per_model=gpus_per_model,
models_to_create=models_to_create,
)
== [ModelDevices("a", ["b"]), ModelDevices("c", ["d"])]
)
assert split_devices_into_model_devices(
devices=devices,
gpus_per_model=gpus_per_model,
models_to_create=models_to_create,
) == [ModelDevices("a", ["b"]), ModelDevices("c", ["d"])]


def test_split_7_devices_3_gpus_per_model():
devices = ["a", "b", "c", "d", "e", "f", "g"]
gpus_per_model = 3
models_to_create = 2
assert (
split_devices_into_model_devices(
devices=devices,
gpus_per_model=gpus_per_model,
models_to_create=models_to_create,
)
== [ModelDevices("a", ["b", "c"]), ModelDevices("d", ["e", "f"])]
)
assert split_devices_into_model_devices(
devices=devices,
gpus_per_model=gpus_per_model,
models_to_create=models_to_create,
) == [ModelDevices("a", ["b", "c"]), ModelDevices("d", ["e", "f"])]
2 changes: 1 addition & 1 deletion tests/test_truncated_eigh.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def random_symmetric_matrix(n: int, k: int) -> torch.Tensor:
assert k <= n, "Rank k should be less than or equal to the matrix size n."

# Generate random n x k matrix A with elements drawn from a uniform distribution
A = torch.rand(n, k) / k ** 0.5
A = torch.rand(n, k) / k**0.5

# Create a diagonal matrix D with k eigenvalues evenly distributed around zero
eigenvalues = torch.linspace(-1, 1, k)
Expand Down

0 comments on commit d108680

Please sign in to comment.