from goodfire import Variant# Create a variant from a base modelvariant = Variant("meta-llama/Llama-3.1-8B-Instruct")# Search for a feature to modifyfeature = client.features.search("formal writing style", model=variant, top_k=1)[0]# Set feature modificationsvariant.set(feature, 0.5) # Value typically between -1 and 1
You can create variants that respond dynamically to feature activations:
Copy
# First get some features to work withwhale_feature = client.features.search("whales", model=variant, top_k=1)[0]pirate_feature = client.features.search("pirate speech", model=variant, top_k=1)[0]# Activate pirate features when whale features are detectedvariant.set_when(whale_feature > 0.75, { pirate_feature: 0.5})# Abort generation if certain features are too strongvariant.abort_when(whale_feature > 0.9)# Custom handler when condition is metdef my_handler(context): print(f"Whale feature activated with strength: {context.activations[whale_feature]}")