Skip to content

Enable InputRecorder to run in offline mode and cuda device #2067

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
28 changes: 19 additions & 9 deletions torchao/_models/_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,27 @@ def __init__(
vocab_size=32000,
pad_token=0,
device="cpu",
online_access=True,
):
try:
super().__init__()
except TypeError:
# lm_eval 0.4.2 removed the default init
super().__init__("gpt2", device="cpu")
if online_access:
try:
super().__init__()
except TypeError:
# lm_eval 0.4.2 removed the default init
super().__init__("gpt2", device=device)
else:
# Create a minimal implementation when run offline
self._device = torch.device(device)
self._max_length = 2048
self._max_gen_toks = 256
self._batch_size = 1

self.tokenizer = tokenizer
self._device = torch.device(device)
self.vocab_size = vocab_size
self._max_seq_length = calibration_seq_length
self.calibration_seq_length = calibration_seq_length
self.online_access = online_access

# need to take inps and convert to corrent input
# for model
Expand Down Expand Up @@ -257,10 +266,11 @@ def record_inputs(
calibration_tasks,
calibration_limit,
):
try:
lm_eval.tasks.initialize_tasks()
except:
pass
if self.online_access:
try:
lm_eval.tasks.initialize_tasks()
except:
pass

task_dict = get_task_dict(calibration_tasks)
print("Obtaining GPTQ calibration inputs on: ", calibration_tasks)
Expand Down
Loading