stanfordnlp / pyvene

Stanford NLP Python Library for Understanding and Improving PyTorch Models via Interventions
http://pyvene.ai
Apache License 2.0
608 stars 59 forks source link

Model generation API simplified and cleanup tech debt on redundant variables #70

Closed frankaging closed 8 months ago

frankaging commented 8 months ago

Descriptions: Simplify generation intervention to have default mode of argument-less with just the base input. The default mode is inference-time intervention where we intervene on each decoding step now.

Cleanup intervention initialization with lazy dict variable passing, instead of hard coded arguments. Refactory existing code for readability.

Testing Done:


WARNING:root:Loading trainable intervention from intkey_layer.0.repr.block_output.unit.pos.nunit.1#0.bin.
WARNING:root:Loading trainable intervention from intkey_layer.1.repr.block_output.unit.pos.nunit.1#0.bin.
Directory './test_output_dir_prefix-9647b9' created successfully.
WARNING:root:Saving trainable intervention to intkey_layer.0.repr.block_output.unit.pos.nunit.1#0.bin.
WARNING:root:Saving trainable intervention to intkey_layer.1.repr.block_output.unit.pos.nunit.1#0.bin.
WARNING:root:The key is provided in the config. Assuming this is loaded from a pretrained module.
WARNING:root:Loading trainable intervention from intkey_layer.0.repr.block_output.unit.pos.nunit.1#0.bin.
WARNING:root:Loading trainable intervention from intkey_layer.1.repr.block_output.unit.pos.nunit.1#0.bin.
.Directory './test_output_dir_prefix-2701e4' created successfully.
.Directory './test_output_dir_prefix-87c463' created successfully.
WARNING:root:Saving trainable intervention to intkey_layer.0.repr.block_output.unit.pos.nunit.1#0.bin.
WARNING:root:Saving trainable intervention to intkey_layer.1.repr.block_output.unit.pos.nunit.1#0.bin.
.Removing testing dir ./test_output_dir_prefix-8f8fad
Removing testing dir ./test_output_dir_prefix-364dae
Removing testing dir ./test_output_dir_prefix-9647b9
Removing testing dir ./test_output_dir_prefix-2701e4
Removing testing dir ./test_output_dir_prefix-87c463

----------------------------------------------------------------------
Ran 31 tests in 84.541s

OK```