Skip to content

Llama AttributeError: 'bool' object has no attribute 'all_special_tokens' #1809

Closed

Description

@mattguida

Hi all,

while fine-tuning LLama3.1-8B-Instruct using Unsloth, I have encountered the following error:

Traceback (most recent call last):
  File "/data/gpfs/projects/punim0478/guida/mfc_fine_tuning/code/multi_label.py", line 226, in <module>
    fine_tuner.main()
  File "/data/gpfs/projects/punim0478/guida/mfc_fine_tuning/code/multi_label.py", line 106, in main
    self.model, self.tokenizer = FastLanguageModel.from_pretrained(
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/gpfs/projects/punim0478/guida/unsloth_env/lib/python3.11/site-packages/unsloth/models/loader.py", line 292, in from_pretrained
    model, tokenizer = dispatch_model.from_pretrained(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/gpfs/projects/punim0478/guida/unsloth_env/lib/python3.11/site-packages/unsloth/models/llama.py", line 1816, in from_pretrained
    tokenizer = load_correct_tokenizer(
                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/gpfs/projects/punim0478/guida/unsloth_env/lib/python3.11/site-packages/unsloth/tokenizer_utils.py", line 557, in load_correct_tokenizer
    tokenizer = _load_correct_tokenizer(
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/gpfs/projects/punim0478/guida/unsloth_env/lib/python3.11/site-packages/unsloth/tokenizer_utils.py", line 536, in _load_correct_tokenizer
    if assert_same_tokenization(slow_tokenizer, fast_tokenizer):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/gpfs/projects/punim0478/guida/unsloth_env/lib/python3.11/site-packages/unsloth/tokenizer_utils.py", line 266, in assert_same_tokenization
    all_special_tokens = list(set(special_tokens + slow_tokenizer.all_special_tokens))
                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'bool' object has no attribute 'all_special_tokens'

Any lead here? Here's how I define my classes:

class MFCFineTuner:
    def __init__(self, model_name, output_dir, save_path, json_output_file, file_name, subset_size):
        self.model_name = model_name
        self.output_dir = output_dir
        self.save_path = save_path
        self.json_output_file = json_output_file
        self.file_name = file_name
        self.subset_size = subset_size

        self.max_seq_length = 1000
        self.dtype = None
        self.load_in_4bit = True
        self.system_instruction = PROMPT_MULTI
        self.alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.

                                ### Instruction:
                                {}

                                ### Input:
                                Text to analyze: {}

                                ### Response:
                                {}"""

        self.model = None
        self.tokenizer = None
        self.EOS_TOKEN = None

def main(self):
        self.model, self.tokenizer = FastLanguageModel.from_pretrained(
            model_name=self.model_name,
            max_seq_length=self.max_seq_length,
            dtype=self.dtype,
            load_in_4bit=self.load_in_4bit,
            cache_dir="/data/gpfs/projects/punim0478/guida/models",
        #    device_map="auto",
        #    trust_remote_code=True
        )

        self.EOS_TOKEN = self.tokenizer.eos_token

Thanks in advance! I have tried to use both the base model (Llama3.1-8B) and the Instruct model, in both cases trying both 8bit or full.

Activity

  1. koleshjr commented on Feb 24, 2025

    @koleshjr

    I am also facing the same issue. I have finetuned this model many times in the past but at the moment I can't due to this error

  2. koleshjr commented on Feb 24, 2025

    @koleshjr

    @mattguida Was able to fix it. Upgrade to the latest Unsloth

  3. mattguida commented on Feb 24, 2025

    @mattguida
    Author

    @koleshjr Thanks! I updated Unsloth too but now I get

    TypeError: SFTTrainer.__init__() got an unexpected keyword argument 'dataset_text_field'

    Which is very confusing..

  4. zuozhenLib commented on Feb 25, 2025

    @zuozhenLib

    same issue, very easy to reproduce this with old version of unsloth

    from accelerate import PartialState
    import torch
    device_string = PartialState().process_index # For DDP device_map
    model, tokenizer = FastLanguageModel.from_pretrained(model_name = "unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit",
                                                            max_seq_length = 512,
                                                            dtype = torch.float16,
                                                            load_in_4bit = True,
                                                            device_map={"": device_string})
    
  5. zuozhenLib commented on Feb 26, 2025

    @zuozhenLib

    @mattguida no need to upgrade the package. add fix_tokenizer=False at your from_pretrained function solve this issue

  6. danielhanchen commented on Feb 26, 2025

    @danielhanchen
    Member

    @mattguida Oh yep dataset_text_field got removed in newer TRL versions. Did you guys also update unsloth-zoo via pip install --upgrade --force-reinstall --no-deps --no-cache-dir unsloth_zoo

  7. ai-nikolai commented on Mar 11, 2025

    @ai-nikolai

    @danielhanchen - could you tell us a working version for installation for both an older version and a newer version.

    It seems like older versions are now broken too - with a plethora of new issues.

  8. oobabooga commented on Jul 28, 2026

    @oobabooga
    Member

    This was fixed by commit 66a1345 ("Fix weird tokenizer issue"), released shortly before this report, so upgrading resolves it.

    On main, _load_correct_tokenizer converts a bool slow_tokenizer to None (unsloth/tokenizer_utils.py:607) and assert_same_tokenization returns early when all_special_tokens is missing (unsloth/tokenizer_utils.py:264). @koleshjr confirmed the same.

    The later dataset_text_field TypeError is a TRL API change, answered above. Closing as fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions