Skip to content

Commit 9717307

Browse files
authored
Validation with full data set, results in NaN validation score (ml-explore#879)
* CLI arguments may set num_batches to -1 The CLI arguments allow you to validate with the entire dataset by passing a negative one value, but this quickly results in a division by zero `NaN` to appear as the validation score! * Must properly assemble the mini batches when validating with entire dataset. Tested locally, a validation of a novel took about an hour, with a loss of 0.928. Thanks @awni for the correction! * Set up the pre-commit hooks and run them so that black may format lora.py.
1 parent 63800c8 commit 9717307

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lora/lora.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,12 @@ def iterate_batches(dset, tokenizer, batch_size, train=False):
220220
def evaluate(model, dataset, loss, tokenizer, batch_size, num_batches):
221221
all_losses = []
222222
ntokens = 0
223+
224+
# num_batches can be -1 to indicate the entire set
225+
index_iterator = iter(range(num_batches)) if num_batches != -1 else iter(int, 1)
226+
223227
for it, batch in zip(
224-
range(num_batches),
228+
index_iterator,
225229
iterate_batches(dataset, tokenizer, batch_size),
226230
):
227231
losses, toks = loss(model, *batch)

0 commit comments

Comments
 (0)