I'm getting the following traceback generating from models using the latest mlx/mlx-examples from git:
Traceback (most recent call last):
[..snip..]
File "/path/to/mlx-examples/llms/mlx_lm/models/base.py", line 39, in create_attention_mask
if cache is not None and cache[0] is not None:
~~~~~^^^
TypeError: 'module' object is not subscriptable
The script below and its invocations demonstrate the error on a random set of text of a given range of sizes, one where most of the generations produce the error and the other where none do. The main distinction between when the error occurs seems to just be the size of the input and not the model ( have tried others)
#!/usr/bin/env python
import click
def get_random_words(lowest_num_words, highest_num_words):
import requests
import random
url = "https://www.mit.edu/~ecprice/wordlist.10000"
response = requests.get(url)
wordlist = response.text.splitlines()
while True:
num_words = random.randint(lowest_num_words, highest_num_words)
selected_words = random.sample(wordlist, num_words)
yield selected_words
@click.command()
@click.option('-l', '--lowest-num-words', default=10, type=int)
@click.option('-u', '--highest-num-words', default=100, type=int)
@click.option('-n', '--num-generations', default=10, type=int)
@click.argument('model')
def main(lowest_num_words, highest_num_words, num_generations, model):
from mlx_lm.utils import load, generate
model, tokenizer = load(model)
errors = {}
for _, words in zip(range(num_generations), get_random_words(lowest_num_words, highest_num_words)):
text = ' '.join(words)
num_words = len(words)
num_tokens = len(tokenizer.encode(text))
print(f"{num_words :,} words, {num_tokens :,} tokens")
try:
generate(model, tokenizer, f"Summarize the text below: \n{text}")
except TypeError as e:
import traceback
errors.setdefault(num_tokens, set()).add(traceback.format_exc())
print(f"Errors in {len(errors):,}/{num_generations:,} . Token lengths: {list(errors)}")
for error_trace in set().union(*errors.values()):
print(error_trace)
if __name__ == "__main__":
main()
I'm getting the following traceback generating from models using the latest mlx/mlx-examples from git:
The script below and its invocations demonstrate the error on a random set of text of a given range of sizes, one where most of the generations produce the error and the other where none do. The main distinction between when the error occurs seems to just be the size of the input and not the model ( have tried others)
Small run
Slightly larger run