Close Menu
techwavedispatch.com

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Nothing’s AI Device Debuts December 8, And It Looks Like Two Vapes Stuck Together

    November 20, 2026

    Why We Should Rethink the Sequential SFT-RL Paradigm

    November 20, 2026

    Chips can survive the space environment. Can their financing?

    November 20, 2026
    Facebook X (Twitter) Instagram
    Trending
    • Nothing’s AI Device Debuts December 8, And It Looks Like Two Vapes Stuck Together
    • Why We Should Rethink the Sequential SFT-RL Paradigm
    • Chips can survive the space environment. Can their financing?
    • Prescribed Bayesian Efficiency under Lifetime Adjustment Costs
    • Robot Videos: Morphing Robots, Dancing Humanoids, More
    • You Can Reveal The Full GTA 6 Map In Minutes Using This Simple Plane Trick
    • State-Space Compression for AI-Based Radio Resource Management of Vehicular Services
    • The 23 Best Early Black Friday Deals: Our Ultimate Picks (2026)
    Facebook X (Twitter) Instagram
    techwavedispatch.com
    Subscribe
    Friday, November 20
    • Home
    • AI Tools & Software
    • Machine Learning
    • Generative AI
    • Robotics & Automation
    • Future Tech & Hardware
    • AI in Business
    • Ethics & Regulations
    • More
      • Gadgets & Smart Devices
      • Cybersecurity & AI
      • Tech Breakthroughs
    techwavedispatch.com
    Home»AI Tools & Software»Hyperparameter Search with Transformers and Ray Tune
    AI Tools & Software

    Hyperparameter Search with Transformers and Ray Tune

    adminBy adminNovember 16, 2026No Comments3 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Hyperparameter Search with Transformers and Ray Tune
    Share
    Facebook Twitter LinkedIn Pinterest Email



    A guest blog post by Richard Liaw from the Anyscale team

    With cutting edge research implementations, thousands of trained models easily accessible, the Hugging Face transformers library has become critical to the success and growth of natural language processing today.

    For any machine learning model to achieve good performance, users often need to implement some form of parameter tuning. Yet, nearly everyone (1, 2) either ends up disregarding hyperparameter tuning or opting to do a simplistic grid search with a small search space.

    However, simple experiments are able to show the benefit of using an advanced tuning technique. Below is a recent experiment run on a BERT model from Hugging Face transformers on the RTE dataset. Genetic optimization techniques like PBT can provide large performance improvements compared to standard hyperparameter optimization techniques.

    Algorithm Best Val Acc. Best Test Acc. Total GPU min Total $ cost
    Grid Search 74% 65.4% 45 min $2.30
    Bayesian Optimization +Early Stop 77% 66.9% 104 min $5.30
    Population-based Training 78% 70.5% 48 min $2.45

    If you’re leveraging Transformers, you’ll want to have a way to easily access powerful hyperparameter tuning solutions without giving up the customizability of the Transformers framework.

    alt_text

    In the Transformers 3.1 release, Hugging Face Transformers and Ray Tune teamed up to provide a simple yet powerful integration. Ray Tune is a popular Python library for hyperparameter tuning that provides many state-of-the-art algorithms out of the box, along with integrations with the best-of-class tooling, such as Weights and Biases and tensorboard.

    To demonstrate this new Hugging Face + Ray Tune integration, we leverage the Hugging Face Datasets library to fine tune BERT on MRPC.

    To run this example, please first run:

    pip install "ray[tune]" transformers datasets scipy sklearn torch

    Simply plug in one of Ray’s standard tuning algorithms by just adding a few lines of code.

    from datasets import load_dataset, load_metric
    from transformers import (AutoModelForSequenceClassification, AutoTokenizer,
                              Trainer, TrainingArguments)
    
    tokenizer = AutoTokenizer.from_pretrained('distilbert-base-uncased')
    dataset = load_dataset('glue', 'mrpc')
    metric = load_metric('glue', 'mrpc')
    
    def encode(examples):
        outputs = tokenizer(
            examples['sentence1'], examples['sentence2'], truncation=True)
        return outputs
    
    encoded_dataset = dataset.map(encode, batched=True)
    
    def model_init():
        return AutoModelForSequenceClassification.from_pretrained(
            'distilbert-base-uncased', return_dict=True)
    
    def compute_metrics(eval_pred):
        predictions, labels = eval_pred
        predictions = predictions.argmax(axis=-1)
        return metric.compute(predictions=predictions, references=labels)
    
    
    
    
    training_args = TrainingArguments(
        "test", evaluation_strategy="steps", eval_steps=500, disable_tqdm=True)
    trainer = Trainer(
        args=training_args,
        tokenizer=tokenizer,
        train_dataset=encoded_dataset["train"],
        eval_dataset=encoded_dataset["validation"],
        model_init=model_init,
        compute_metrics=compute_metrics,
    )
    
    
    
    trainer.hyperparameter_search(
        direction="maximize", 
        backend="ray", 
        n_trials=10 
    )
    

    By default, each trial will utilize 1 CPU, and optionally 1 GPU if available.
    You can leverage multiple GPUs for a parallel hyperparameter search
    by passing in a resources_per_trial argument.

    You can also easily swap different parameter tuning algorithms such as HyperBand, Bayesian Optimization, Population-Based Training:

    To run this example, first run: pip install hyperopt

    from ray.tune.suggest.hyperopt import HyperOptSearch
    from ray.tune.schedulers import ASHAScheduler
    
    trainer = Trainer(
        args=training_args,
        tokenizer=tokenizer,
        train_dataset=encoded_dataset["train"],
        eval_dataset=encoded_dataset["validation"],
        model_init=model_init,
        compute_metrics=compute_metrics,
    )
    
    best_trial = trainer.hyperparameter_search(
        direction="maximize",
        backend="ray",
        
        
        search_alg=HyperOptSearch(metric="objective", mode="max"),
        
        
        scheduler=ASHAScheduler(metric="objective", mode="max"))
    

    It also works with Weights and Biases out of the box!

    alt_text



    Try it out today:

    If you liked this blog post, be sure to check out:

    Hyperparameter Ray search Transformers Tune
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    admin
    • Website

    Related Posts

    Bloomberg analysis of 10 million job postings shows AI-exposed roles in China fell 10 percentage points faster than others

    November 20, 2026

    Apple joins the race for AI agents that control your device while raising new barriers for competitors

    November 20, 2026

    Nvidia bets at least $500 million on Inception’s diffusion models to strengthen its open-source Nemotron lineup

    November 20, 2026
    Leave A Reply Cancel Reply

    Top Posts

    NVIDIA Is Investigating Reports That CEO Jensen Huang Was The Target Of Chinese Spy Efforts

    November 8, 202619 Views

    ADIndex: Layer-Adaptive Sparse Attention Indexing via Group-Level Distillation

    November 11, 20265 Views

    Anthropic releases new Mythos and Fable models amid RSI concerns

    November 9, 20265 Views

    If AGI is so close, why is everyone leaving? The neolabs and their bets

    November 6, 20265 Views
    Don't Miss
    Gadgets & Smart Devices

    Nothing’s AI Device Debuts December 8, And It Looks Like Two Vapes Stuck Together

    By adminNovember 20, 20260

    Thanks, Swedish House Mafia. I guess.  Nothing In classic Carl Pei…

    Why We Should Rethink the Sequential SFT-RL Paradigm

    November 20, 2026

    Chips can survive the space environment. Can their financing?

    November 20, 2026

    Prescribed Bayesian Efficiency under Lifetime Adjustment Costs

    November 20, 2026
    About Us

    Welcome to TechWave Dispatch

    At TechWave Dispatch, we bring you the latest news, insights, and developments from the ever-evolving world of technology. Our mission is to keep readers informed about the innovations shaping our digital future.

    From artificial intelligence and machine learning to cybersecurity, robotics, smart devices, and groundbreaking technologies, we cover the topics that matter in today's fast-moving tech landscape.

    Our Picks

    Nothing’s AI Device Debuts December 8, And It Looks Like Two Vapes Stuck Together

    November 20, 2026

    Why We Should Rethink the Sequential SFT-RL Paradigm

    November 20, 2026

    Chips can survive the space environment. Can their financing?

    November 20, 2026
    Most Popular

    After blocking Muse, Amazon now lets users text Alexa to help them shop

    November 6, 20260 Views

    A controlled world for robot learning and evaluation

    November 6, 20260 Views

    Perplexity now has its own always-on AI agent

    November 6, 20260 Views
    Facebook X (Twitter) Instagram Pinterest
    • Terms and Conditions
    • Privacy Policy
    • Contact Us
    • About Us
    © 2026 TechWave Dispatch. All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.