Hypster Docs
Github 🌟Contact Us
  • 👋Welcome
  • Getting Started
    • 🖥️Installation
    • 🚀Defining of A Config Function
    • ⚡Instantiating a Config Function
    • 🍡Selecting Output Variables
    • 🎮Interactive Instantiation (UI)
    • 🪄Usage Examples
      • Machine Learning
      • LLM Generation
  • In Depth
    • 🤖Parameter Naming
    • 🍱HP Call Types
      • Selectable Types
      • Numeric Types
      • Boolean Types
      • Textual Types
      • Nested Configurations
    • 🧠Best Practices
Powered by GitBook

Contact & Follow the Author

  • Website
  • LinkedIn
  • Github
  • Medium

© Gilad Rubin 2024

On this page

Was this helpful?

Edit on GitHub
  1. Getting Started

Selecting Output Variables

When working with configuration functions, not all variables defined within them are needed for the final execution engine.

Consider this configuration function:

from hypster import config, HP

@config
def llm_config(hp: HP):
    model_name = hp.select({"sonnet" : "claude-3-5-sonnet-20241022"
                            "haiku" : "claude-3-5-haiku-20241022"}, 
                            default="haiku")
    
    if model_type == "haiku":
        max_tokens = hp.int(256, max=2048)
    else:
        max_tokens = hp.int(126, max=1024)
        
    cache = Cache(folder=hp.text("./cache"))
    config_dct = {"temperature" : hp.number(0, min=0, max=1),
                  "max_tokens" : max_tokens}
              
    model = Model(model_name, cache)

Along with this execution function:

def run(input: str, model: Model, config_dict: Dict[str, Any]) -> str:
    return model.run(input, **config_dict)

This function only requires model and config_dict, but our configuration function creates additional variables like cache, model_type, and param. Passing unnecessary variables could:

  • Cause function signature mismatches

  • Lead to memory inefficiency

  • Create potential naming conflicts

Variable Selection Methods

To ensure we pass only the required variables, we have two filtering approaches:

  1. Include specific variables using final_vars:

config = my_config(final_vars=["model", "config_dict"], values={...})
run("Hello", **config)

Use final_vars when you need only a few specific variables

When final_vars is empty, all variables are returned (except those in exclude_vars)

  1. Exclude unwanted variables using exclude_vars:

config = my_config(exclude_vars=["cache", "temp_data"], values={...})
run("Hello", **config)

Choose exclude_vars when you have many variables to keep and little to filter out.

PreviousInstantiating a Config FunctionNextInteractive Instantiation (UI)

Last updated 6 months ago

Was this helpful?

🍡