Muqeeth commited on
Commit
bf7ac4e
·
verified ·
1 Parent(s): 1e094b7

Add files using upload-large-folder tool

Browse files
Files changed (50) hide show
  1. .hydra/config.yaml +168 -0
  2. .hydra/hydra.yaml +154 -0
  3. .hydra/overrides.yaml +1 -0
  4. seed_1337/Qwen/Qwen2.5-7B-Instruct/adapters/README.md +207 -0
  5. seed_1337/Qwen/Qwen2.5-7B-Instruct/adapters/agent_adapter/adapter_config.json +46 -0
  6. src_code_for_reproducibility/__init__.py +4 -0
  7. src_code_for_reproducibility/chat_utils/__pycache__/chat_turn.cpython-312.pyc +0 -0
  8. src_code_for_reproducibility/markov_games/__init__.py +4 -0
  9. src_code_for_reproducibility/markov_games/agent.py +72 -0
  10. src_code_for_reproducibility/markov_games/alternative_actions_runner.py +146 -0
  11. src_code_for_reproducibility/markov_games/group_timesteps.py +133 -0
  12. src_code_for_reproducibility/markov_games/ipd/__pycache__/__init__.cpython-312.pyc +0 -0
  13. src_code_for_reproducibility/markov_games/ipd/__pycache__/ipd_agent.cpython-312.pyc +0 -0
  14. src_code_for_reproducibility/markov_games/ipd/__pycache__/ipd_simulation.cpython-312.pyc +0 -0
  15. src_code_for_reproducibility/markov_games/ipd/__pycache__/ipd_statistics.cpython-312.pyc +0 -0
  16. src_code_for_reproducibility/markov_games/markov_game.py +217 -0
  17. src_code_for_reproducibility/markov_games/negotiation/__pycache__/nego_hard_coded_policies.cpython-312.pyc +0 -0
  18. src_code_for_reproducibility/markov_games/negotiation/__pycache__/no_press_nego_agent.cpython-312.pyc +0 -0
  19. src_code_for_reproducibility/markov_games/rollout_tree.py +95 -0
  20. src_code_for_reproducibility/models/__pycache__/__init__.cpython-312.pyc +0 -0
  21. src_code_for_reproducibility/models/__pycache__/adapter_training_wrapper.cpython-312.pyc +0 -0
  22. src_code_for_reproducibility/models/__pycache__/human_policy.cpython-312.pyc +0 -0
  23. src_code_for_reproducibility/models/__pycache__/inference_backend.cpython-312.pyc +0 -0
  24. src_code_for_reproducibility/models/__pycache__/inference_backend_dummy.cpython-312.pyc +0 -0
  25. src_code_for_reproducibility/models/__pycache__/inference_backend_vllm.cpython-312.pyc +0 -0
  26. src_code_for_reproducibility/models/__pycache__/large_language_model_api.cpython-312.pyc +0 -0
  27. src_code_for_reproducibility/models/__pycache__/large_language_model_local.cpython-312.pyc +0 -0
  28. src_code_for_reproducibility/models/__pycache__/scalar_critic.cpython-312.pyc +0 -0
  29. src_code_for_reproducibility/training/__pycache__/__init__.cpython-312.pyc +0 -0
  30. src_code_for_reproducibility/training/__pycache__/annealing_methods.cpython-312.pyc +0 -0
  31. src_code_for_reproducibility/training/__pycache__/credit_methods.cpython-312.pyc +0 -0
  32. src_code_for_reproducibility/training/__pycache__/tally_metrics.cpython-312.pyc +0 -0
  33. src_code_for_reproducibility/training/__pycache__/tally_rollout.cpython-312.pyc +0 -0
  34. src_code_for_reproducibility/training/__pycache__/tally_tokenwise.cpython-312.pyc +0 -0
  35. src_code_for_reproducibility/training/__pycache__/tokenize_chats.cpython-312.pyc +0 -0
  36. src_code_for_reproducibility/training/__pycache__/trainer_ad_align.cpython-312.pyc +0 -0
  37. src_code_for_reproducibility/training/__pycache__/trainer_common.cpython-312.pyc +0 -0
  38. src_code_for_reproducibility/training/__pycache__/trainer_independent.cpython-312.pyc +0 -0
  39. src_code_for_reproducibility/training/__pycache__/trainer_sum_rewards.cpython-312.pyc +0 -0
  40. src_code_for_reproducibility/training/__pycache__/training_data_utils.cpython-312.pyc +0 -0
  41. src_code_for_reproducibility/utils/__pycache__/__init__.cpython-312.pyc +0 -0
  42. src_code_for_reproducibility/utils/__pycache__/dict_get_path.cpython-312.pyc +0 -0
  43. src_code_for_reproducibility/utils/__pycache__/get_coagent_id.cpython-312.pyc +0 -0
  44. src_code_for_reproducibility/utils/__pycache__/resource_context.cpython-312.pyc +0 -0
  45. src_code_for_reproducibility/utils/__pycache__/rollout_tree_gather_utils.cpython-312.pyc +0 -0
  46. src_code_for_reproducibility/utils/__pycache__/rollout_tree_stats.cpython-312.pyc +0 -0
  47. src_code_for_reproducibility/utils/__pycache__/short_id_gen.cpython-312.pyc +0 -0
  48. src_code_for_reproducibility/utils/__pycache__/stat_pack.cpython-312.pyc +0 -0
  49. src_code_for_reproducibility/utils/__pycache__/update_start_epoch.cpython-312.pyc +0 -0
  50. src_code_for_reproducibility/utils/__pycache__/wandb_utils.cpython-312.pyc +0 -0
.hydra/config.yaml ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ experiment:
2
+ wandb_enabled: true
3
+ nb_epochs: 3000
4
+ nb_matches_per_iteration: 64
5
+ reinit_matches_each_it: true
6
+ checkpoint_every_n_iterations: 50
7
+ start_epoch: 0
8
+ resume_experiment: true
9
+ base_seed: 1337
10
+ seed_group_size: 8
11
+ train: true
12
+ stat_methods_for_live_wandb: mllm.markov_games.negotiation.negotiation_statistics
13
+ name: split_no_comm_naive_seed1337
14
+ agent_buffer: false
15
+ keep_agent_buffer_count: ${lora_count}
16
+ agent_buffer_recent_k: -1
17
+ logging:
18
+ wandb:
19
+ enabled: false
20
+ project: llm-negotiation
21
+ entity: null
22
+ mode: online
23
+ name: null
24
+ group: null
25
+ tags: []
26
+ notes: null
27
+ temperature: 1.0
28
+ markov_games:
29
+ runner_method_name: LinearRunner
30
+ runner_kwargs: {}
31
+ group_by_round: true
32
+ simulation_class_name: NoPressSimulation
33
+ simulation_init_args:
34
+ nb_of_rounds: 10
35
+ quota_messages_per_agent_per_round: 0
36
+ game_type: 10-1-ties
37
+ atleast_one_conflict: true
38
+ item_types:
39
+ - hats
40
+ - books
41
+ - balls
42
+ agents:
43
+ 0:
44
+ agent_id: ${agent_0_id}
45
+ agent_name: Alice
46
+ agent_class_name: NoPressAgent
47
+ policy_id: base_llm/agent_adapter
48
+ init_kwargs:
49
+ goal: Maximize your total points over the whole game.
50
+ 1:
51
+ agent_id: ${agent_1_id}
52
+ agent_name: Bob
53
+ agent_class_name: NoPressAgent
54
+ policy_id: base_llm/agent_adapter
55
+ init_kwargs:
56
+ goal: Maximize your total points over the whole game.
57
+ models:
58
+ base_llm:
59
+ class: LeanLocalLLM
60
+ init_args:
61
+ llm_id: base_llm
62
+ model_name: Qwen/Qwen2.5-7B-Instruct
63
+ inference_backend: vllm
64
+ hf_kwargs:
65
+ device_map: auto
66
+ torch_dtype: bfloat16
67
+ max_memory:
68
+ 0: 20GiB
69
+ attn_implementation: flash_attention_2
70
+ inference_backend_init_kwargs:
71
+ enable_lora: true
72
+ seed: ${experiment.base_seed}
73
+ enable_prefix_caching: true
74
+ max_model_len: 10000.0
75
+ gpu_memory_utilization: 0.5
76
+ dtype: bfloat16
77
+ trust_remote_code: true
78
+ max_lora_rank: 32
79
+ enforce_eager: false
80
+ max_loras: ${lora_count}
81
+ max_cpu_loras: ${lora_count}
82
+ enable_sleep_mode: true
83
+ inference_backend_sampling_params:
84
+ temperature: ${temperature}
85
+ top_p: 1.0
86
+ max_tokens: 400
87
+ top_k: -1
88
+ logprobs: 0
89
+ adapter_configs:
90
+ agent_adapter:
91
+ task_type: CAUSAL_LM
92
+ r: 32
93
+ lora_alpha: 64
94
+ lora_dropout: 0.0
95
+ target_modules: all-linear
96
+ critic_adapter:
97
+ task_type: CAUSAL_LM
98
+ r: 32
99
+ lora_alpha: 64
100
+ lora_dropout: 0.0
101
+ target_modules: all-linear
102
+ enable_thinking: null
103
+ regex_max_attempts: 3
104
+ critics:
105
+ agent_critic:
106
+ module_pointer:
107
+ - base_llm
108
+ - critic_adapter
109
+ optimizers:
110
+ agent_optimizer:
111
+ module_pointer:
112
+ - base_llm
113
+ - agent_adapter
114
+ optimizer_class_name: torch.optim.Adam
115
+ init_args:
116
+ lr: 3.0e-06
117
+ weight_decay: 0.0
118
+ critic_optimizer:
119
+ module_pointer: agent_critic
120
+ optimizer_class_name: torch.optim.Adam
121
+ init_args:
122
+ lr: 3.0e-06
123
+ weight_decay: 0.0
124
+ trainers:
125
+ agent_trainer:
126
+ class: TrainerNaive
127
+ module_pointers:
128
+ policy:
129
+ - base_llm
130
+ - agent_adapter
131
+ policy_optimizer: agent_optimizer
132
+ critic: agent_critic
133
+ critic_optimizer: critic_optimizer
134
+ kwargs:
135
+ entropy_coeff: 0.0
136
+ entropy_topk: null
137
+ entropy_mask_regex: null
138
+ kl_coeff: 0.001
139
+ gradient_clipping: 1.0
140
+ restrict_tokens: null
141
+ mini_batch_size: 1
142
+ use_gradient_checkpointing: false
143
+ temperature: ${temperature}
144
+ device: cuda:0
145
+ use_gae: false
146
+ whiten_advantages: false
147
+ whiten_advantages_time_step_wise: false
148
+ skip_discounted_state_visitation: true
149
+ use_gae_lambda_annealing: false
150
+ gae_lambda_annealing_method: None
151
+ gae_lambda_annealing_method_params: None
152
+ gae_lambda_annealing_limit: 0.95
153
+ discount_factor: 0.9
154
+ use_rloo: true
155
+ enable_tokenwise_logging: false
156
+ pg_loss_normalization: nb_tokens
157
+ truncated_importance_sampling_ratio_cap: 2.0
158
+ reward_normalizing_constant: 100.0
159
+ train_on_which_data:
160
+ agent_trainer: ${agent_ids}
161
+ lora_count: 30
162
+ common_agent_kwargs:
163
+ goal: Maximize your total points over the whole game.
164
+ agent_0_id: Alice
165
+ agent_1_id: Bob
166
+ agent_ids:
167
+ - Alice
168
+ - Bob
.hydra/hydra.yaml ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ hydra:
2
+ run:
3
+ dir: ${oc.env:SCRATCH}/llm_negotiation/${now:%Y_%m}/${experiment.name}
4
+ sweep:
5
+ dir: multirun/${now:%Y-%m-%d}/${now:%H-%M-%S}
6
+ subdir: ${hydra.job.num}
7
+ launcher:
8
+ _target_: hydra._internal.core_plugins.basic_launcher.BasicLauncher
9
+ sweeper:
10
+ _target_: hydra._internal.core_plugins.basic_sweeper.BasicSweeper
11
+ max_batch_size: null
12
+ params: null
13
+ help:
14
+ app_name: ${hydra.job.name}
15
+ header: '${hydra.help.app_name} is powered by Hydra.
16
+
17
+ '
18
+ footer: 'Powered by Hydra (https://hydra.cc)
19
+
20
+ Use --hydra-help to view Hydra specific help
21
+
22
+ '
23
+ template: '${hydra.help.header}
24
+
25
+ == Configuration groups ==
26
+
27
+ Compose your configuration from those groups (group=option)
28
+
29
+
30
+ $APP_CONFIG_GROUPS
31
+
32
+
33
+ == Config ==
34
+
35
+ Override anything in the config (foo.bar=value)
36
+
37
+
38
+ $CONFIG
39
+
40
+
41
+ ${hydra.help.footer}
42
+
43
+ '
44
+ hydra_help:
45
+ template: 'Hydra (${hydra.runtime.version})
46
+
47
+ See https://hydra.cc for more info.
48
+
49
+
50
+ == Flags ==
51
+
52
+ $FLAGS_HELP
53
+
54
+
55
+ == Configuration groups ==
56
+
57
+ Compose your configuration from those groups (For example, append hydra/job_logging=disabled
58
+ to command line)
59
+
60
+
61
+ $HYDRA_CONFIG_GROUPS
62
+
63
+
64
+ Use ''--cfg hydra'' to Show the Hydra config.
65
+
66
+ '
67
+ hydra_help: ???
68
+ hydra_logging:
69
+ version: 1
70
+ formatters:
71
+ simple:
72
+ format: '[%(asctime)s][HYDRA] %(message)s'
73
+ handlers:
74
+ console:
75
+ class: logging.StreamHandler
76
+ formatter: simple
77
+ stream: ext://sys.stdout
78
+ root:
79
+ level: INFO
80
+ handlers:
81
+ - console
82
+ loggers:
83
+ logging_example:
84
+ level: DEBUG
85
+ disable_existing_loggers: false
86
+ job_logging:
87
+ version: 1
88
+ formatters:
89
+ simple:
90
+ format: '[%(asctime)s][%(name)s][%(levelname)s] - %(message)s'
91
+ handlers:
92
+ console:
93
+ class: logging.StreamHandler
94
+ formatter: simple
95
+ stream: ext://sys.stdout
96
+ file:
97
+ class: logging.FileHandler
98
+ formatter: simple
99
+ filename: ${hydra.runtime.output_dir}/${hydra.job.name}.log
100
+ root:
101
+ level: INFO
102
+ handlers:
103
+ - console
104
+ - file
105
+ disable_existing_loggers: false
106
+ env: {}
107
+ mode: RUN
108
+ searchpath: []
109
+ callbacks: {}
110
+ output_subdir: .hydra
111
+ overrides:
112
+ hydra:
113
+ - hydra.mode=RUN
114
+ task: []
115
+ job:
116
+ name: run
117
+ chdir: false
118
+ override_dirname: ''
119
+ id: ???
120
+ num: ???
121
+ config_name: split_no_comm_naive_seed1337.yaml
122
+ env_set: {}
123
+ env_copy: []
124
+ config:
125
+ override_dirname:
126
+ kv_sep: '='
127
+ item_sep: ','
128
+ exclude_keys: []
129
+ runtime:
130
+ version: 1.3.2
131
+ version_base: '1.1'
132
+ cwd: /lustre10/scratch/muqeeth/AdAlignLLM
133
+ config_sources:
134
+ - path: hydra.conf
135
+ schema: pkg
136
+ provider: hydra
137
+ - path: /lustre10/scratch/muqeeth/AdAlignLLM/configs
138
+ schema: file
139
+ provider: main
140
+ - path: ''
141
+ schema: structured
142
+ provider: schema
143
+ output_dir: /scratch/muqeeth/llm_negotiation/2026_03/split_no_comm_naive_seed1337
144
+ choices:
145
+ hydra/env: default
146
+ hydra/callbacks: null
147
+ hydra/job_logging: default
148
+ hydra/hydra_logging: default
149
+ hydra/hydra_help: default
150
+ hydra/help: default
151
+ hydra/sweeper: basic
152
+ hydra/launcher: basic
153
+ hydra/output: default
154
+ verbose: false
.hydra/overrides.yaml ADDED
@@ -0,0 +1 @@
 
 
1
+ []
seed_1337/Qwen/Qwen2.5-7B-Instruct/adapters/README.md ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ base_model: Qwen/Qwen2.5-7B-Instruct
3
+ library_name: peft
4
+ pipeline_tag: text-generation
5
+ tags:
6
+ - base_model:adapter:Qwen/Qwen2.5-7B-Instruct
7
+ - lora
8
+ - transformers
9
+ ---
10
+
11
+ # Model Card for Model ID
12
+
13
+ <!-- Provide a quick summary of what the model is/does. -->
14
+
15
+
16
+
17
+ ## Model Details
18
+
19
+ ### Model Description
20
+
21
+ <!-- Provide a longer summary of what this model is. -->
22
+
23
+
24
+
25
+ - **Developed by:** [More Information Needed]
26
+ - **Funded by [optional]:** [More Information Needed]
27
+ - **Shared by [optional]:** [More Information Needed]
28
+ - **Model type:** [More Information Needed]
29
+ - **Language(s) (NLP):** [More Information Needed]
30
+ - **License:** [More Information Needed]
31
+ - **Finetuned from model [optional]:** [More Information Needed]
32
+
33
+ ### Model Sources [optional]
34
+
35
+ <!-- Provide the basic links for the model. -->
36
+
37
+ - **Repository:** [More Information Needed]
38
+ - **Paper [optional]:** [More Information Needed]
39
+ - **Demo [optional]:** [More Information Needed]
40
+
41
+ ## Uses
42
+
43
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
44
+
45
+ ### Direct Use
46
+
47
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
48
+
49
+ [More Information Needed]
50
+
51
+ ### Downstream Use [optional]
52
+
53
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
54
+
55
+ [More Information Needed]
56
+
57
+ ### Out-of-Scope Use
58
+
59
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
60
+
61
+ [More Information Needed]
62
+
63
+ ## Bias, Risks, and Limitations
64
+
65
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
66
+
67
+ [More Information Needed]
68
+
69
+ ### Recommendations
70
+
71
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
72
+
73
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
74
+
75
+ ## How to Get Started with the Model
76
+
77
+ Use the code below to get started with the model.
78
+
79
+ [More Information Needed]
80
+
81
+ ## Training Details
82
+
83
+ ### Training Data
84
+
85
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
86
+
87
+ [More Information Needed]
88
+
89
+ ### Training Procedure
90
+
91
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
92
+
93
+ #### Preprocessing [optional]
94
+
95
+ [More Information Needed]
96
+
97
+
98
+ #### Training Hyperparameters
99
+
100
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
101
+
102
+ #### Speeds, Sizes, Times [optional]
103
+
104
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
105
+
106
+ [More Information Needed]
107
+
108
+ ## Evaluation
109
+
110
+ <!-- This section describes the evaluation protocols and provides the results. -->
111
+
112
+ ### Testing Data, Factors & Metrics
113
+
114
+ #### Testing Data
115
+
116
+ <!-- This should link to a Dataset Card if possible. -->
117
+
118
+ [More Information Needed]
119
+
120
+ #### Factors
121
+
122
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
123
+
124
+ [More Information Needed]
125
+
126
+ #### Metrics
127
+
128
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
129
+
130
+ [More Information Needed]
131
+
132
+ ### Results
133
+
134
+ [More Information Needed]
135
+
136
+ #### Summary
137
+
138
+
139
+
140
+ ## Model Examination [optional]
141
+
142
+ <!-- Relevant interpretability work for the model goes here -->
143
+
144
+ [More Information Needed]
145
+
146
+ ## Environmental Impact
147
+
148
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
149
+
150
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
151
+
152
+ - **Hardware Type:** [More Information Needed]
153
+ - **Hours used:** [More Information Needed]
154
+ - **Cloud Provider:** [More Information Needed]
155
+ - **Compute Region:** [More Information Needed]
156
+ - **Carbon Emitted:** [More Information Needed]
157
+
158
+ ## Technical Specifications [optional]
159
+
160
+ ### Model Architecture and Objective
161
+
162
+ [More Information Needed]
163
+
164
+ ### Compute Infrastructure
165
+
166
+ [More Information Needed]
167
+
168
+ #### Hardware
169
+
170
+ [More Information Needed]
171
+
172
+ #### Software
173
+
174
+ [More Information Needed]
175
+
176
+ ## Citation [optional]
177
+
178
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
179
+
180
+ **BibTeX:**
181
+
182
+ [More Information Needed]
183
+
184
+ **APA:**
185
+
186
+ [More Information Needed]
187
+
188
+ ## Glossary [optional]
189
+
190
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
191
+
192
+ [More Information Needed]
193
+
194
+ ## More Information [optional]
195
+
196
+ [More Information Needed]
197
+
198
+ ## Model Card Authors [optional]
199
+
200
+ [More Information Needed]
201
+
202
+ ## Model Card Contact
203
+
204
+ [More Information Needed]
205
+ ### Framework versions
206
+
207
+ - PEFT 0.18.1
seed_1337/Qwen/Qwen2.5-7B-Instruct/adapters/agent_adapter/adapter_config.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": null,
6
+ "base_model_name_or_path": "Qwen/Qwen2.5-7B-Instruct",
7
+ "bias": "none",
8
+ "corda_config": null,
9
+ "ensure_weight_tying": false,
10
+ "eva_config": null,
11
+ "exclude_modules": null,
12
+ "fan_in_fan_out": false,
13
+ "inference_mode": true,
14
+ "init_lora_weights": true,
15
+ "layer_replication": null,
16
+ "layers_pattern": null,
17
+ "layers_to_transform": null,
18
+ "loftq_config": {},
19
+ "lora_alpha": 64,
20
+ "lora_bias": false,
21
+ "lora_dropout": 0.0,
22
+ "megatron_config": null,
23
+ "megatron_core": "megatron.core",
24
+ "modules_to_save": null,
25
+ "peft_type": "LORA",
26
+ "peft_version": "0.18.1",
27
+ "qalora_group_size": 16,
28
+ "r": 32,
29
+ "rank_pattern": {},
30
+ "revision": null,
31
+ "target_modules": [
32
+ "o_proj",
33
+ "down_proj",
34
+ "v_proj",
35
+ "k_proj",
36
+ "gate_proj",
37
+ "q_proj",
38
+ "up_proj"
39
+ ],
40
+ "target_parameters": null,
41
+ "task_type": "CAUSAL_LM",
42
+ "trainable_token_indices": null,
43
+ "use_dora": false,
44
+ "use_qalora": false,
45
+ "use_rslora": false
46
+ }
src_code_for_reproducibility/__init__.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ """
2
+ File: mllm/__init__.py
3
+ Summary: Initializes the multi-agent large language model package namespace.
4
+ """
src_code_for_reproducibility/chat_utils/__pycache__/chat_turn.cpython-312.pyc ADDED
Binary file (1.46 kB). View file
 
src_code_for_reproducibility/markov_games/__init__.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ """
2
+ File: mllm/markov_games/__init__.py
3
+ Summary: Makes Markov-game subpackages importable from the top-level namespace.
4
+ """
src_code_for_reproducibility/markov_games/agent.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ File: mllm/markov_games/agent.py
3
+ Summary: Declares the base Agent interface connecting simulations to policy calls.
4
+ """
5
+
6
+ from abc import ABC, abstractmethod
7
+ from collections.abc import Callable
8
+ from typing import Any, Tuple
9
+
10
+ from numpy.random import default_rng
11
+
12
+ from mllm.markov_games.rollout_tree import AgentActLog
13
+
14
+
15
+ class Agent(ABC):
16
+ """Abstract policy wrapper that bridges simulations with arbitrary backends."""
17
+
18
+ @abstractmethod
19
+ def __init__(
20
+ self,
21
+ seed: int,
22
+ agent_id: str,
23
+ agent_name: str,
24
+ agent_policy: Callable[[list[dict]], str],
25
+ *args,
26
+ **kwargs,
27
+ ):
28
+ """
29
+ Initialize the agent state and seed its RNG.
30
+
31
+ Subclasses typically store extra handles (tokenizers, inference clients, etc.)
32
+ but they should always call ``super().__init__`` so sampling remains reproducible.
33
+ """
34
+ self.seed = seed
35
+ self.agent_id = agent_id
36
+ self.agent_name = agent_name
37
+ self.policy = policy
38
+ self.rng = default_rng(self.seed)
39
+ raise NotImplementedError
40
+
41
+ async def act(self, observation) -> Tuple[Any, AgentActLog]:
42
+ """
43
+ Produce the next action (and associated chat log) given an environment observation.
44
+
45
+ Implementations can iterate with rejection sampling, multi-call deliberation, etc.
46
+ Returns both the chosen action and an `AgentActLog` describing how it was produced.
47
+ """
48
+ raise NotImplementedError
49
+
50
+ def get_safe_copy(self):
51
+ """
52
+ Return a deep copy whose future calls do not mutate the original agent.
53
+
54
+ Needed for branch exploration/reruns with alternative actions.
55
+ """
56
+ raise NotImplementedError
57
+
58
+ def reset(self):
59
+ """Reset any internal state between rollouts."""
60
+ raise NotImplementedError
61
+
62
+ def render(self):
63
+ """Optional human-readable visualization of the agent (CLI/UI)."""
64
+ raise NotImplementedError
65
+
66
+ def close(self):
67
+ """Release any external resources (network sockets, subprocesses, etc.)."""
68
+ raise NotImplementedError
69
+
70
+ def get_agent_info(self):
71
+ """Return diagnostic metadata to embed inside rollout logs."""
72
+ raise NotImplementedError
src_code_for_reproducibility/markov_games/alternative_actions_runner.py ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ File: mllm/markov_games/alternative_actions_runner.py
3
+ Summary: Generates rollout branches by replaying trajectories with unilateral action changes.
4
+ """
5
+
6
+ import asyncio
7
+ import copy
8
+ import json
9
+ import os.path
10
+ from typing import Any, Tuple
11
+
12
+ from mllm.markov_games.markov_game import AgentAndActionSafeCopy, MarkovGame
13
+ from mllm.markov_games.rollout_tree import (
14
+ AgentActLog,
15
+ RolloutTreeBranchNode,
16
+ RolloutTreeNode,
17
+ RolloutTreeRootNode,
18
+ StepLog,
19
+ )
20
+
21
+ AgentId = str
22
+
23
+
24
+ async def run_with_unilateral_alt_action(
25
+ markov_game: MarkovGame,
26
+ agent_id: AgentId,
27
+ time_step: int,
28
+ branch_node: RolloutTreeBranchNode,
29
+ max_depth: int,
30
+ ):
31
+ """
32
+ Roll out a counterfactual branch where ``agent_id`` deviates unilaterally.
33
+
34
+ Starting from ``branch_node`` (which already contains the main trajectory),
35
+ we replay the simulation with the deviating agent's action while freezing
36
+ all other agents/actions, then continue for ``max_depth`` steps.
37
+ """
38
+
39
+ # Generate alternative action and take a step
40
+ await markov_game.set_action_of_agent(agent_id)
41
+ terminated: bool = markov_game.take_simulation_step()
42
+ step_log = markov_game.get_step_log()
43
+ first_alternative_node = RolloutTreeNode(
44
+ step_log=step_log,
45
+ time_step=time_step,
46
+ )
47
+
48
+ # Generate rest of trajectory up to max depth
49
+ time_step += 1
50
+ counter = 1
51
+ previous_node = first_alternative_node
52
+ while not terminated and counter <= max_depth:
53
+ terminated, step_log = await markov_game.step()
54
+ current_node = RolloutTreeNode(step_log=step_log, time_step=time_step)
55
+ previous_node.child = current_node
56
+ previous_node = current_node
57
+ counter += 1
58
+ time_step += 1
59
+
60
+ if branch_node.branches == None:
61
+ branch_node.branches = {agent_id: [first_alternative_node]}
62
+ else:
63
+ agent_branches = branch_node.branches.get(agent_id, [])
64
+ agent_branches.append(first_alternative_node)
65
+ branch_node.branches[agent_id] = agent_branches
66
+
67
+
68
+ async def AlternativeActionsRunner(
69
+ markov_game: MarkovGame,
70
+ output_folder: str,
71
+ nb_alternative_actions: int,
72
+ max_depth: int,
73
+ branch_only_on_new_round: bool = False,
74
+ ):
75
+ """
76
+ Generate a rollout tree containing the main path plus unilateral deviation branches.
77
+
78
+ For each timestep we:
79
+ 1. Cache agent actions without side effects.
80
+ 2. Advance the main trajectory.
81
+ 3. Spawn ``nb_alternative_actions`` asynchronous deviations per agent,
82
+ each replaying up to ``max_depth`` steps from the cached pre-action state.
83
+ The resulting branches feed advantage-alignment estimators.
84
+ """
85
+
86
+ tasks = []
87
+ time_step = 0
88
+ terminated = False
89
+ root = RolloutTreeRootNode(id=markov_game.get_id(), crn_id=markov_game.get_crn_id())
90
+ previous_node = root
91
+
92
+ while not terminated:
93
+ mg_before_action = markov_game.get_safe_copy()
94
+
95
+ # Get safe copies for main branch
96
+ agent_action_safe_copies: dict[
97
+ AgentId, AgentAndActionSafeCopy
98
+ ] = await markov_game.get_actions_of_agents_without_side_effects()
99
+
100
+ markov_game.set_actions_of_agents_manually(agent_action_safe_copies)
101
+ terminated = markov_game.take_simulation_step()
102
+ main_node = RolloutTreeNode(
103
+ step_log=markov_game.get_step_log(), time_step=time_step
104
+ )
105
+ branch_node = RolloutTreeBranchNode(main_child=main_node)
106
+ previous_node.child = branch_node
107
+ previous_node = main_node
108
+
109
+ # Get alternative branches by generating new unilateral actions
110
+ for agent_id in markov_game.agent_ids:
111
+ for _ in range(nb_alternative_actions):
112
+ # Get safe copies for branches
113
+ branch_agent_action_safe_copies: dict[
114
+ AgentId, AgentAndActionSafeCopy
115
+ ] = {
116
+ agent_id: AgentAndActionSafeCopy(
117
+ action=copy.deepcopy(agent_action_safe_copy.action),
118
+ action_info=copy.deepcopy(agent_action_safe_copy.action_info),
119
+ agent_after_action=agent_action_safe_copy.agent_after_action.get_safe_copy(),
120
+ )
121
+ for agent_id, agent_action_safe_copy in agent_action_safe_copies.items()
122
+ }
123
+ mg_branch: MarkovGame = mg_before_action.get_safe_copy()
124
+ other_agent_id = [id for id in mg_branch.agent_ids if id != agent_id][0]
125
+ mg_branch.set_action_and_agent_after_action_manually(
126
+ agent_id=other_agent_id,
127
+ agent_action_safe_copy=branch_agent_action_safe_copies[
128
+ other_agent_id
129
+ ],
130
+ )
131
+ task = asyncio.create_task(
132
+ run_with_unilateral_alt_action(
133
+ markov_game=mg_branch,
134
+ time_step=time_step,
135
+ agent_id=agent_id,
136
+ branch_node=branch_node,
137
+ max_depth=max_depth,
138
+ )
139
+ )
140
+ tasks.append(task)
141
+ time_step += 1
142
+
143
+ # wait for all branches to complete
144
+ await asyncio.gather(*tasks)
145
+
146
+ return root
src_code_for_reproducibility/markov_games/group_timesteps.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ File: mllm/markov_games/group_timesteps.py
3
+ Summary: Provides timestep-grouping utilities for rollout trees and training.
4
+ """
5
+
6
+ import copy
7
+ from typing import Callable
8
+
9
+ from mllm.markov_games.markov_game import MarkovGame
10
+ from mllm.markov_games.rollout_tree import (
11
+ AgentActLog,
12
+ RolloutTreeBranchNode,
13
+ RolloutTreeNode,
14
+ RolloutTreeRootNode,
15
+ StepLog,
16
+ )
17
+ from mllm.markov_games.simulation import SimulationStepLog
18
+
19
+ AgentId = str
20
+
21
+
22
+ def group_time_steps(
23
+ rollout_tree: RolloutTreeRootNode,
24
+ accumulation_stop_condition: Callable[[StepLog], bool],
25
+ ) -> RolloutTreeRootNode:
26
+ """
27
+ During generation, we create rollout trees according to the real time steps.
28
+ However, during training, we might want to treat groups of time steps as a single time step.
29
+ As a concrete example, take Trust-and-Split. At each round, say we have X time steps of communication and then one time step for the split.
30
+ Then the communication actions will not get any reward, and the split action will get the reward. During REINFORCE training, with discounting, this
31
+ can cause training instability. We could instead treat every action in the round as being part of a single action, and give it the reward of the split action.
32
+ This method helps to do this sort of grouping.
33
+ It accumulates actions until the accumulation_stop_condition is met, and then creates a new node with the accumulated actions.
34
+ It then recursively calls itself on the child node.
35
+ Details:
36
+ - The reward for the group is the reward of the last time step in the group.
37
+ - The simulation log for the group is the simulation log of the last time step in the group.
38
+ - The state end for the group becomes the first state end in the group.
39
+ - The agent info for the group is the agent info of the last time step in the group.
40
+ """
41
+
42
+ def group_step_logs(step_logs: list[StepLog]) -> StepLog:
43
+ """
44
+ Concatenate per-agent chat turns across steps; keep only the first is_state_end.
45
+ """
46
+ last_sim_log = step_logs[-1].simulation_step_log
47
+ agent_ids = {aid for s in step_logs for aid in s.action_logs.keys()}
48
+ grouped_logs: dict[AgentId, AgentActLog] = {}
49
+ for aid in agent_ids:
50
+ turns = []
51
+ for s in step_logs:
52
+ act = s.action_logs.get(aid)
53
+ if act and act.chat_turns:
54
+ turns.extend(copy.deepcopy(act.chat_turns))
55
+ disable_is_state_end = False
56
+ # Only the first state_end should be True, the rest should be False
57
+ for t in turns:
58
+ if t.is_state_end:
59
+ if disable_is_state_end:
60
+ t.is_state_end = False
61
+ else:
62
+ disable_is_state_end = True
63
+ continue
64
+ grouped_logs[aid] = AgentActLog(
65
+ chat_turns=turns, info=step_logs[-1].action_logs[aid].info
66
+ )
67
+ return StepLog(action_logs=grouped_logs, simulation_step_log=last_sim_log)
68
+
69
+ def group_time_steps_rec(
70
+ current_node: RolloutTreeNode | RolloutTreeBranchNode,
71
+ group_time_step: int,
72
+ accumulation_step_logs: list[StepLog],
73
+ ) -> RolloutTreeNode | RolloutTreeBranchNode:
74
+ """
75
+ Groups time steps. Recursion is used to handle branches.
76
+ """
77
+ assert isinstance(current_node, RolloutTreeNode) or isinstance(
78
+ current_node, RolloutTreeBranchNode
79
+ ), "Current node must be a tree node or a branch node. Is of type: " + str(
80
+ type(current_node)
81
+ )
82
+ first_group_node = None
83
+ current_group_node = None
84
+ while current_node is not None:
85
+ if isinstance(current_node, RolloutTreeBranchNode):
86
+ raise Exception(
87
+ "Grouping timesteps by round is not supported for branching trajectories yet."
88
+ )
89
+
90
+ # Accumulate
91
+ accumulation_step_logs.append(current_node.step_log)
92
+ if accumulation_stop_condition(current_node.step_log):
93
+ grouped_step_logs = group_step_logs(accumulation_step_logs)
94
+ accumulation_step_logs = []
95
+ new_group_node = RolloutTreeNode(
96
+ step_log=grouped_step_logs, time_step=group_time_step, child=None
97
+ )
98
+ if first_group_node == None:
99
+ first_group_node = new_group_node
100
+ group_time_step += 1
101
+ if current_group_node is not None:
102
+ current_group_node.child = new_group_node
103
+ current_group_node = new_group_node
104
+ current_node = current_node.child
105
+ return first_group_node
106
+
107
+ node = group_time_steps_rec(
108
+ current_node=rollout_tree.child, group_time_step=0, accumulation_step_logs=[]
109
+ )
110
+ return RolloutTreeRootNode(
111
+ id=rollout_tree.id,
112
+ crn_id=rollout_tree.crn_id,
113
+ child=node,
114
+ agent_ids=rollout_tree.agent_ids,
115
+ )
116
+
117
+
118
+ def stop_when_round_ends(step_log: StepLog) -> bool:
119
+ """
120
+ Simplest stop condition. Will return True if step log is the last time step of a round.
121
+ This will throw an error if this information is not available in the simulation info.
122
+ """
123
+ assert (
124
+ "is_last_timestep_in_round" in step_log.simulation_step_log.info.keys()
125
+ ), "To group by round, is_last_timestep_in_round must be set in the info of your simulation step log at each time step."
126
+ return step_log.simulation_step_log.info["is_last_timestep_in_round"]
127
+
128
+
129
+ def group_by_round(rollout_tree: RolloutTreeRootNode) -> RolloutTreeRootNode:
130
+ """
131
+ Groups time steps by round.
132
+ """
133
+ return group_time_steps(rollout_tree, stop_when_round_ends)
src_code_for_reproducibility/markov_games/ipd/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (435 Bytes). View file
 
src_code_for_reproducibility/markov_games/ipd/__pycache__/ipd_agent.cpython-312.pyc ADDED
Binary file (4.97 kB). View file
 
src_code_for_reproducibility/markov_games/ipd/__pycache__/ipd_simulation.cpython-312.pyc ADDED
Binary file (6.87 kB). View file
 
src_code_for_reproducibility/markov_games/ipd/__pycache__/ipd_statistics.cpython-312.pyc ADDED
Binary file (1.42 kB). View file
 
src_code_for_reproducibility/markov_games/markov_game.py ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ File: mllm/markov_games/markov_game.py
3
+ Summary: Defines the MarkovGame base class plus shared simulation interfaces.
4
+ """
5
+
6
+ import asyncio
7
+ import copy
8
+ import json
9
+ import os
10
+ from dataclasses import dataclass
11
+ from typing import Any, List, Literal, Optional, Tuple
12
+
13
+ from transformers.models.idefics2 import Idefics2Config
14
+
15
+ from mllm.markov_games.agent import Agent
16
+ from mllm.markov_games.rollout_tree import AgentActLog, StepLog
17
+ from mllm.markov_games.simulation import Simulation
18
+
19
+ AgentId = str
20
+
21
+
22
+ @dataclass
23
+ class AgentAndActionSafeCopy:
24
+ """Snapshot of an agent, its action, and metadata used for branch replay."""
25
+
26
+ action: Any
27
+ action_info: AgentActLog
28
+ agent_after_action: type[Agent]
29
+
30
+
31
+ class MarkovGame(object):
32
+ def __init__(
33
+ self,
34
+ id: int,
35
+ agents: dict[AgentId, type[Agent]],
36
+ simulation: type[Simulation],
37
+ crn_id: int,
38
+ ):
39
+ """
40
+ Initialize the Markov game wrapper.
41
+
42
+ Parameters
43
+ ----------
44
+ id:
45
+ Unique rollout identifier (logged into rollout trees).
46
+ agents:
47
+ Mapping of agent_id -> Agent instance.
48
+ simulation:
49
+ Environment implementing the ``Simulation`` interface (IPD, TAS, etc.).
50
+ crn_id:
51
+ Identifier for the common random number stream used by this rollout.
52
+ """
53
+ self.agents = agents
54
+ self.agent_ids = self.agents.keys()
55
+ self.simulation = simulation
56
+ self.simulation_step_log = None
57
+ self.agent_step_logs = {agent_id: None for agent_id in self.agent_ids}
58
+ self.actions = {}
59
+ self.id = id
60
+ self.crn_id = crn_id
61
+
62
+ def get_id(self) -> str:
63
+ return self.id
64
+
65
+ def get_crn_id(self) -> int:
66
+ return self.crn_id
67
+
68
+ def get_agent_ids(self) -> List[AgentId]:
69
+ return list(self.agent_ids)
70
+
71
+ async def get_action_of_agent_without_side_effects(
72
+ self, agent_id: AgentId
73
+ ) -> Tuple[Any, AgentActLog]:
74
+ """
75
+ Safe function to get an action of an agent without modifying the agent or the simulation.
76
+ """
77
+ agent = self.agents[agent_id]
78
+ agent_before_action = agent.get_safe_copy()
79
+ obs = self.simulation.get_obs_agent(agent_id)
80
+ action, action_info = await agent.act(observation=obs)
81
+ self.agents[agent_id] = agent_before_action
82
+ agent_after_action = agent.get_safe_copy()
83
+ return AgentAndActionSafeCopy(action, action_info, agent_after_action)
84
+
85
+ async def get_actions_of_agents_without_side_effects(
86
+ self,
87
+ ) -> dict[AgentId, AgentAndActionSafeCopy]:
88
+ """
89
+ Safe function to get an action of an agent without modifying the agent or the simulation.
90
+ """
91
+ tasks = []
92
+ for agent_id in self.agent_ids:
93
+ task = asyncio.create_task(
94
+ self.get_action_of_agent_without_side_effects(agent_id)
95
+ )
96
+ tasks.append(task)
97
+ agent_and_action_safe_copies: list[
98
+ AgentAndActionSafeCopy
99
+ ] = await asyncio.gather(*tasks)
100
+ return {
101
+ agent_id: agent_and_action_safe_copy
102
+ for agent_id, agent_and_action_safe_copy in zip(
103
+ self.agent_ids, agent_and_action_safe_copies
104
+ )
105
+ }
106
+
107
+ def set_action_and_agent_after_action_manually(
108
+ self,
109
+ agent_id: AgentId,
110
+ agent_action_safe_copy: AgentAndActionSafeCopy,
111
+ ):
112
+ """
113
+ Set the action and the agent after action manually.
114
+ """
115
+ self.actions[agent_id] = agent_action_safe_copy.action
116
+ self.agent_step_logs[agent_id] = agent_action_safe_copy.action_info
117
+ self.agents[agent_id] = agent_action_safe_copy.agent_after_action
118
+
119
+ def set_actions_of_agents_manually(
120
+ self, actions: dict[AgentId, AgentAndActionSafeCopy]
121
+ ):
122
+ """
123
+ Set the actions of agents manually.
124
+ """
125
+ for agent_id, agent_action_safe_copy in actions.items():
126
+ self.set_action_and_agent_after_action_manually(
127
+ agent_id, agent_action_safe_copy
128
+ )
129
+
130
+ async def set_action_of_agent(self, agent_id: AgentId):
131
+ """
132
+ Query a single agent for its next action and store the result locally.
133
+ """
134
+ agent = self.agents[agent_id]
135
+ obs = self.simulation.get_obs_agent(agent_id)
136
+ action, action_info = await agent.act(observation=obs)
137
+ self.actions[agent_id] = action
138
+ self.agent_step_logs[agent_id] = action_info
139
+
140
+ async def set_actions(self):
141
+ """
142
+ Query every agent concurrently and populate the cached actions/logs.
143
+ """
144
+ # background_tasks = set()
145
+ tasks = []
146
+ for agent_id in self.agent_ids:
147
+ task = asyncio.create_task(self.set_action_of_agent(agent_id))
148
+ tasks.append(task)
149
+ await asyncio.gather(*tasks)
150
+
151
+ def take_simulation_step(self):
152
+ """
153
+ Advance the simulation by one step using the cached actions.
154
+ """
155
+ terminated, self.simulation_step_log = self.simulation.step(self.actions)
156
+ return terminated
157
+
158
+ def get_step_log(self) -> StepLog:
159
+ """
160
+ Package the most recent simulation step and agent logs into a StepLog.
161
+ """
162
+ if self.simulation_step_log is None:
163
+ raise RuntimeError(
164
+ "Simulation step log is empty; call take_simulation_step() first."
165
+ )
166
+ missing_logs = [
167
+ agent_id for agent_id, log in self.agent_step_logs.items() if log is None
168
+ ]
169
+ if missing_logs:
170
+ raise RuntimeError(
171
+ f"Agent action logs missing for: {', '.join(missing_logs)}. "
172
+ "Ensure set_actions() ran before requesting the step log."
173
+ )
174
+ step_log = StepLog(
175
+ simulation_step_log=self.simulation_step_log,
176
+ action_logs=self.agent_step_logs,
177
+ )
178
+ return step_log
179
+
180
+ async def step(self) -> Tuple[bool, StepLog]:
181
+ """
182
+ Convenience step that collects actions, advances the simulation, and returns the log.
183
+ """
184
+ await self.set_actions()
185
+ terminated = self.take_simulation_step()
186
+ step_log = self.get_step_log()
187
+ return terminated, step_log
188
+
189
+ def get_safe_copy(self):
190
+ """
191
+ Create a shallow copy of the game with deep-copied agents/simulation for branching.
192
+ """
193
+
194
+ new_markov_game = copy.copy(self)
195
+ new_simulation = self.simulation.get_safe_copy()
196
+ new_agents = {
197
+ agent_id: agent.get_safe_copy() for agent_id, agent in self.agents.items()
198
+ }
199
+
200
+ # Reassign copied components
201
+ new_markov_game.simulation = new_simulation
202
+ new_markov_game.agents = new_agents
203
+
204
+ # IMPORTANT: ensure agent_ids references the new agents dict, not the original
205
+ new_markov_game.agent_ids = new_markov_game.agents.keys()
206
+
207
+ # Deep-copy step data to avoid correlation
208
+ new_markov_game.simulation_step_log = copy.deepcopy(self.simulation_step_log)
209
+ new_markov_game.actions = copy.deepcopy(self.actions)
210
+ # Rebuild logs to align exactly with new agent ids
211
+ old_agent_step_logs = copy.deepcopy(self.agent_step_logs)
212
+ new_markov_game.agent_step_logs = {
213
+ agent_id: old_agent_step_logs.get(agent_id)
214
+ for agent_id in new_markov_game.agent_ids
215
+ }
216
+
217
+ return new_markov_game
src_code_for_reproducibility/markov_games/negotiation/__pycache__/nego_hard_coded_policies.cpython-312.pyc ADDED
Binary file (3.39 kB). View file
 
src_code_for_reproducibility/markov_games/negotiation/__pycache__/no_press_nego_agent.cpython-312.pyc ADDED
Binary file (6.11 kB). View file
 
src_code_for_reproducibility/markov_games/rollout_tree.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ File: mllm/markov_games/rollout_tree.py
3
+ Summary: Defines rollout tree data structures and serialization helpers.
4
+ """
5
+
6
+ from __future__ import annotations
7
+
8
+ import json
9
+ from dataclasses import dataclass
10
+ from pathlib import Path
11
+ from typing import Any, List, Literal, Optional, Tuple
12
+
13
+ import jsonschema
14
+ from pydantic import BaseModel, Field, model_validator
15
+
16
+ from mllm.chat_utils.chat_turn import ChatTurn
17
+
18
+ AgentId = str
19
+
20
+
21
+ class SimulationStepLog(BaseModel):
22
+ """Minimal snapshot of environment-side rewards and auxiliary info."""
23
+
24
+ rewards: dict[AgentId, float]
25
+ info: Any = None
26
+
27
+
28
+ class AgentActLog(BaseModel):
29
+ """LLM-side provenance for an action (chat turns + metadata)."""
30
+
31
+ chat_turns: list[ChatTurn] | None
32
+ info: Any = None
33
+
34
+ @model_validator(mode="after")
35
+ def _exactly_one_state_end(self):
36
+ """
37
+ This method is used to enforce that for each AgentActLog, there is exactly one ChatTurn which is a state end.
38
+ """
39
+ if self.chat_turns != []:
40
+ n = sum(1 for t in self.chat_turns if t.is_state_end)
41
+ if n != 1:
42
+ raise ValueError(
43
+ f"AgentActLog must have exactly one ChatTurn with is_state_end=True; got {self.chat_turns}."
44
+ )
45
+ return self
46
+ else:
47
+ return self
48
+
49
+
50
+ class StepLog(BaseModel):
51
+ action_logs: dict[AgentId, AgentActLog]
52
+ simulation_step_log: SimulationStepLog
53
+
54
+
55
+ # BranchType = Literal["unilateral_deviation", "common_deviation"] # might not be necessary
56
+ # class BranchNodeInfo(BaseModel):
57
+ # branch_id: str
58
+ # branch_for: AgentId
59
+ # branch_type: BranchType
60
+
61
+
62
+ class RolloutTreeNode(BaseModel):
63
+ """Single timestep of the main trajectory (or a branch) plus linkage."""
64
+
65
+ step_log: StepLog
66
+ time_step: int
67
+ child: RolloutTreeNode | RolloutTreeBranchNode | None = None
68
+
69
+
70
+ class RolloutTreeBranchNode(BaseModel):
71
+ """
72
+ First item of the tuple indicates which agent "called" for an alternative branch.
73
+ """
74
+
75
+ main_child: RolloutTreeNode
76
+ branches: dict[AgentId, list[RolloutTreeNode]] | None = None
77
+
78
+
79
+ class RolloutTreeRootNode(BaseModel):
80
+ """Entry point for serialized rollouts (main path plus optional branches)."""
81
+
82
+ id: int
83
+ crn_id: int # ID of the rng used to generate this rollout tree
84
+ child: RolloutTreeNode | RolloutTreeBranchNode | None = None
85
+ agent_ids: List[AgentId] = Field(min_length=1)
86
+
87
+
88
+ # class RolloutTreeLeafNode(BaseModel):
89
+ # step_log: StepLog
90
+ # time_step: int
91
+
92
+
93
+ # Necessary for self-referential stuff in pydantic
94
+ RolloutTreeBranchNode.model_rebuild()
95
+ RolloutTreeNode.model_rebuild()
src_code_for_reproducibility/models/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (269 Bytes). View file
 
src_code_for_reproducibility/models/__pycache__/adapter_training_wrapper.cpython-312.pyc ADDED
Binary file (5.06 kB). View file
 
src_code_for_reproducibility/models/__pycache__/human_policy.cpython-312.pyc ADDED
Binary file (12.1 kB). View file
 
src_code_for_reproducibility/models/__pycache__/inference_backend.cpython-312.pyc ADDED
Binary file (2.38 kB). View file
 
src_code_for_reproducibility/models/__pycache__/inference_backend_dummy.cpython-312.pyc ADDED
Binary file (2.49 kB). View file
 
src_code_for_reproducibility/models/__pycache__/inference_backend_vllm.cpython-312.pyc ADDED
Binary file (5.12 kB). View file
 
src_code_for_reproducibility/models/__pycache__/large_language_model_api.cpython-312.pyc ADDED
Binary file (7.08 kB). View file
 
src_code_for_reproducibility/models/__pycache__/large_language_model_local.cpython-312.pyc ADDED
Binary file (16.5 kB). View file
 
src_code_for_reproducibility/models/__pycache__/scalar_critic.cpython-312.pyc ADDED
Binary file (3.32 kB). View file
 
src_code_for_reproducibility/training/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (277 Bytes). View file
 
src_code_for_reproducibility/training/__pycache__/annealing_methods.cpython-312.pyc ADDED
Binary file (965 Bytes). View file
 
src_code_for_reproducibility/training/__pycache__/credit_methods.cpython-312.pyc ADDED
Binary file (12.8 kB). View file
 
src_code_for_reproducibility/training/__pycache__/tally_metrics.cpython-312.pyc ADDED
Binary file (3.48 kB). View file
 
src_code_for_reproducibility/training/__pycache__/tally_rollout.cpython-312.pyc ADDED
Binary file (6.01 kB). View file
 
src_code_for_reproducibility/training/__pycache__/tally_tokenwise.cpython-312.pyc ADDED
Binary file (13.5 kB). View file
 
src_code_for_reproducibility/training/__pycache__/tokenize_chats.cpython-312.pyc ADDED
Binary file (5.98 kB). View file
 
src_code_for_reproducibility/training/__pycache__/trainer_ad_align.cpython-312.pyc ADDED
Binary file (19.8 kB). View file
 
src_code_for_reproducibility/training/__pycache__/trainer_common.cpython-312.pyc ADDED
Binary file (40.3 kB). View file
 
src_code_for_reproducibility/training/__pycache__/trainer_independent.cpython-312.pyc ADDED
Binary file (6.72 kB). View file
 
src_code_for_reproducibility/training/__pycache__/trainer_sum_rewards.cpython-312.pyc ADDED
Binary file (6.02 kB). View file
 
src_code_for_reproducibility/training/__pycache__/training_data_utils.cpython-312.pyc ADDED
Binary file (20.4 kB). View file
 
src_code_for_reproducibility/utils/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (253 Bytes). View file
 
src_code_for_reproducibility/utils/__pycache__/dict_get_path.cpython-312.pyc ADDED
Binary file (665 Bytes). View file
 
src_code_for_reproducibility/utils/__pycache__/get_coagent_id.cpython-312.pyc ADDED
Binary file (556 Bytes). View file
 
src_code_for_reproducibility/utils/__pycache__/resource_context.cpython-312.pyc ADDED
Binary file (4.68 kB). View file
 
src_code_for_reproducibility/utils/__pycache__/rollout_tree_gather_utils.cpython-312.pyc ADDED
Binary file (12.7 kB). View file
 
src_code_for_reproducibility/utils/__pycache__/rollout_tree_stats.cpython-312.pyc ADDED
Binary file (2.38 kB). View file
 
src_code_for_reproducibility/utils/__pycache__/short_id_gen.cpython-312.pyc ADDED
Binary file (718 Bytes). View file
 
src_code_for_reproducibility/utils/__pycache__/stat_pack.cpython-312.pyc ADDED
Binary file (7.75 kB). View file
 
src_code_for_reproducibility/utils/__pycache__/update_start_epoch.cpython-312.pyc ADDED
Binary file (1 kB). View file
 
src_code_for_reproducibility/utils/__pycache__/wandb_utils.cpython-312.pyc ADDED
Binary file (6.66 kB). View file