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

TypeError: bad operand type for unary -: 'NoneType' #47

Open
wln20 opened this issue Aug 7, 2024 · 0 comments
Open

TypeError: bad operand type for unary -: 'NoneType' #47

wln20 opened this issue Aug 7, 2024 · 0 comments

Comments

@wln20
Copy link

wln20 commented Aug 7, 2024

An error occurred when I tried to run Mistral-7b-instruct-v0.2 model:

...
  File "~/anaconda/envs/streamingllm/lib/python3.9/site-packages/transformers/models/mistral/modeling_mistral.py", line 88, in _make_sliding_window_causal_mask
    mask = torch.triu(mask, diagonal=-sliding_window)
TypeError: bad operand type for unary -: 'NoneType'

I inspected the position causing the error and found the sliding_window is None here. I noticed that the problem raised because the model.model.config.sliding_window attribution is None and doesn't get the correct value. Therefore I manually set it after the instantiation of the model, and the code seems to run correctly:

sliding_window = 252
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    # for efficiency:
    device_map="auto",
    torch_dtype=torch.float16,
    # `attention_sinks`-specific arguments:
    attention_sink_size=4,
    attention_sink_window_size=sliding_window, # <- Low for the sake of faster generation
)
model.model.config.sliding_window = sliding_window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant