Skip to content

Unsloth models output gibberish on LONG inputs #2405

Closed

Description

@SreevaatsavB

I tried inference on a very long input with models like llama 3.1 8B (both 4 bit quantised and unquantised).
The input to the model was around ~50K tokens. Some documents were dumped into the context, thus resulting in such large inputs.

Considering llama 3.1's 128K context size and the RoPE scaling

The output is just some tokens with a repeated pattern. The same model works decently on smaller inputs, but completely crashes for long ones.

I've attached the screenshot of the same. Please check it out.

The same model works perfectly fine on the same input on other platforms such as togetherai, hf, etc

Can anyone help me with this issue?

SS1 :-
Image

Activity

  1. changed the title [-][Bug] Unsloth models output gibberish on LONG inputs[/-] [+]Unsloth models output gibberish on LONG inputs[/+] on Apr 24, 2025
  2. shimmyshimmer commented on Apr 26, 2025

    @shimmyshimmer
    Member
  3. SreevaatsavB commented on Apr 28, 2025

    @SreevaatsavB
    Author

    Yes i am using the right tokenizer and the padding config...

  4. Charley-xiao commented on Apr 30, 2025

    @Charley-xiao

    Same here. Using Llama3-8B-Instruct with SIMPLE_CHAT_TEMPLATE from trl:

    Image

    Here's my code:

    model, tokenizer = FastModel.from_pretrained(
        model_name=args.orchestrator,
        load_in_4bit = True,
        device_map="auto",
        full_finetuning=False,
    )
    
    model = FastLanguageModel.get_peft_model(
        model,
        r=16,
        target_modules=["q_proj", "k_proj", "v_proj", "o_proj",
                      "gate_proj", "up_proj", "down_proj",],
        lora_alpha=16,
        lora_dropout=0,
        bias="none",
        use_gradient_checkpointing="unsloth",
        random_state=3407,
        max_seq_length=1024,
        use_rslora=False,
        loftq_config=None,
    )
    
    if not args.only_test:
        training_args = GRPOConfig(
            output_dir=str(args.output_dir),
            learning_rate = 5e-6,
            adam_beta1 = 0.9,
            adam_beta2 = 0.99,
            weight_decay = 0.1,
            warmup_ratio = 0.1,
            lr_scheduler_type = "cosine",
            optim = "adamw_8bit",
            num_generations=4,
            max_steps = 250,
            save_steps = 250,
            max_grad_norm = 0.1,
            logging_steps = 1,
            remove_unused_columns=False,  # we keep `label` for the reward fn
            # load_best_model_at_end=True,
            max_prompt_length = 256,
            max_completion_length = 1024 - 256,
            # save_safetensors=False,
            # eval_strategy="steps",
        )
    
        trainer = GRPOTrainer(
            model=model,
            reward_funcs=[reward_fn, soft_format_reward_func],
            args=training_args,
            train_dataset=train_dataset,
            # eval_dataset=val_dataset,
            processing_class=tokenizer,
        )
    
        logging.info("⇢  Starting GRPO training …")
        trainer.train()
        trainer.save_model()
        tokenizer.save_pretrained(args.output_dir)
        logging.info(f"Training complete - checkpoints written to {args.output_dir}")
  5. Charley-xiao commented on Apr 30, 2025

    @Charley-xiao

    Ah I solved it by changing model, tokenizer = FastModel.from_pretrained(...) to model, tokenizer = FastLanguageModel.from_pretrained(...)

  6. github-actions commented on Jul 1, 2025

    @github-actions
    Contributor

    Is this issue still important to you? Apologies in advance we might have missed this issue as well. For faster response times, please post on our Reddit server - https://www.reddit.com/r/unsloth or our Discord - https://discord.com/invite/unsloth

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions