oliverdk commited on
Commit
995430d
1 Parent(s): d4af455

End of training

Browse files
.hydra/config.yaml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ model:
2
+ dataset_name: redwoodresearch/diamonds-seed7
3
+ model_type: codegen
4
+ pretrained_model_name: Salesforce/codegen-350M-mono
5
+ max_length: 1024
6
+ hparams:
7
+ learning_rate: 2.0e-05
8
+ weight_decay: 0.02
9
+ lr_scheduler_type: cosine
10
+ warmup_steps: 64
11
+ effective_batch_size: 32
12
+ num_train_epochs: 5
13
+ per_device_train_batch_size: 4
14
+ per_device_eval_batch_size: 4
15
+ fp16: true
16
+ dataset_len: null
17
+ push_to_hub: true
.hydra/hydra.yaml ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ hydra:
2
+ run:
3
+ dir: outputs/${now:%Y-%m-%d}/${now:%H-%M-%S}
4
+ sweep:
5
+ dir: multirun/${now:%Y-%m-%d}/${now:%H-%M-%S}
6
+ subdir: ${hydra.job.num}
7
+ launcher:
8
+ submitit_folder: ${hydra.sweep.dir}/.submitit/%j
9
+ timeout_min: 1440
10
+ cpus_per_task: null
11
+ gpus_per_node: null
12
+ tasks_per_node: 1
13
+ mem_gb: 16
14
+ nodes: 1
15
+ name: ${hydra.job.name}
16
+ stderr_to_stdout: false
17
+ _target_: hydra_plugins.hydra_submitit_launcher.submitit_launcher.SlurmLauncher
18
+ partition: null
19
+ qos: high
20
+ comment: null
21
+ constraint: null
22
+ exclude: ddpg.ist.berkeley.edu,dqn.ist.berkeley.edu
23
+ gres: gpu:A6000:1
24
+ cpus_per_gpu: null
25
+ gpus_per_task: null
26
+ mem_per_gpu: null
27
+ mem_per_cpu: null
28
+ account: null
29
+ signal_delay_s: 120
30
+ max_num_timeout: 0
31
+ additional_parameters: {}
32
+ array_parallelism: 256
33
+ setup: null
34
+ sweeper:
35
+ _target_: hydra._internal.core_plugins.basic_sweeper.BasicSweeper
36
+ max_batch_size: null
37
+ params: null
38
+ help:
39
+ app_name: ${hydra.job.name}
40
+ header: '${hydra.help.app_name} is powered by Hydra.
41
+
42
+ '
43
+ footer: 'Powered by Hydra (https://hydra.cc)
44
+
45
+ Use --hydra-help to view Hydra specific help
46
+
47
+ '
48
+ template: '${hydra.help.header}
49
+
50
+ == Configuration groups ==
51
+
52
+ Compose your configuration from those groups (group=option)
53
+
54
+
55
+ $APP_CONFIG_GROUPS
56
+
57
+
58
+ == Config ==
59
+
60
+ Override anything in the config (foo.bar=value)
61
+
62
+
63
+ $CONFIG
64
+
65
+
66
+ ${hydra.help.footer}
67
+
68
+ '
69
+ hydra_help:
70
+ template: 'Hydra (${hydra.runtime.version})
71
+
72
+ See https://hydra.cc for more info.
73
+
74
+
75
+ == Flags ==
76
+
77
+ $FLAGS_HELP
78
+
79
+
80
+ == Configuration groups ==
81
+
82
+ Compose your configuration from those groups (For example, append hydra/job_logging=disabled
83
+ to command line)
84
+
85
+
86
+ $HYDRA_CONFIG_GROUPS
87
+
88
+
89
+ Use ''--cfg hydra'' to Show the Hydra config.
90
+
91
+ '
92
+ hydra_help: ???
93
+ hydra_logging:
94
+ version: 1
95
+ formatters:
96
+ simple:
97
+ format: '[%(asctime)s][HYDRA] %(message)s'
98
+ handlers:
99
+ console:
100
+ class: logging.StreamHandler
101
+ formatter: simple
102
+ stream: ext://sys.stdout
103
+ root:
104
+ level: INFO
105
+ handlers:
106
+ - console
107
+ loggers:
108
+ logging_example:
109
+ level: DEBUG
110
+ disable_existing_loggers: false
111
+ job_logging:
112
+ version: 1
113
+ formatters:
114
+ simple:
115
+ format: '[%(asctime)s][%(name)s][%(levelname)s] - %(message)s'
116
+ handlers:
117
+ console:
118
+ class: logging.StreamHandler
119
+ formatter: simple
120
+ stream: ext://sys.stdout
121
+ file:
122
+ class: logging.FileHandler
123
+ formatter: simple
124
+ filename: ${hydra.runtime.output_dir}/${hydra.job.name}.log
125
+ root:
126
+ level: INFO
127
+ handlers:
128
+ - console
129
+ - file
130
+ disable_existing_loggers: false
131
+ env: {}
132
+ mode: MULTIRUN
133
+ searchpath: []
134
+ callbacks: {}
135
+ output_subdir: .hydra
136
+ overrides:
137
+ hydra:
138
+ - hydra.mode=MULTIRUN
139
+ task:
140
+ - model.dataset_name=redwoodresearch/diamonds-seed7
141
+ job:
142
+ name: train
143
+ chdir: null
144
+ override_dirname: model.dataset_name=redwoodresearch/diamonds-seed7
145
+ id: '746836'
146
+ num: 0
147
+ config_name: codegen_diamonds_slurm
148
+ env_set: {}
149
+ env_copy: []
150
+ config:
151
+ override_dirname:
152
+ kv_sep: '='
153
+ item_sep: ','
154
+ exclude_keys: []
155
+ runtime:
156
+ version: 1.3.2
157
+ version_base: '1.1'
158
+ cwd: /nas/ucb/oliveradk/measurement-pred
159
+ config_sources:
160
+ - path: hydra.conf
161
+ schema: pkg
162
+ provider: hydra
163
+ - path: /nas/ucb/oliveradk/measurement-pred/conf
164
+ schema: file
165
+ provider: main
166
+ - path: ''
167
+ schema: structured
168
+ provider: schema
169
+ output_dir: /nas/ucb/oliveradk/measurement-pred/multirun/2024-12-16/18-53-11/0
170
+ choices:
171
+ hparams: hparams
172
+ model: codegen_diamonds
173
+ hydra/env: default
174
+ hydra/callbacks: null
175
+ hydra/job_logging: default
176
+ hydra/hydra_logging: default
177
+ hydra/hydra_help: default
178
+ hydra/help: default
179
+ hydra/sweeper: basic
180
+ hydra/launcher: slurm_chai
181
+ hydra/output: default
182
+ verbose: false
.hydra/overrides.yaml ADDED
@@ -0,0 +1 @@
 
 
1
+ - model.dataset_name=redwoodresearch/diamonds-seed7
README.md ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: bsd-3-clause
3
+ base_model: Salesforce/codegen-350M-mono
4
+ tags:
5
+ - generated_from_trainer
6
+ metrics:
7
+ - accuracy
8
+ model-index:
9
+ - name: codegen-350M-mono-measurement_pred-diamonds-seed7
10
+ results: []
11
+ ---
12
+
13
+ <!-- This model card has been generated automatically according to the information the Trainer had access to. You
14
+ should probably proofread and complete it, then remove this comment. -->
15
+
16
+ # codegen-350M-mono-measurement_pred-diamonds-seed7
17
+
18
+ This model is a fine-tuned version of [Salesforce/codegen-350M-mono](https://huggingface.co/Salesforce/codegen-350M-mono) on an unknown dataset.
19
+ It achieves the following results on the evaluation set:
20
+ - Loss: 0.4759
21
+ - Accuracy: 0.9018
22
+ - Accuracy Sensor 0: 0.9093
23
+ - Auroc Sensor 0: 0.9563
24
+ - Accuracy Sensor 1: 0.9046
25
+ - Auroc Sensor 1: 0.9558
26
+ - Accuracy Sensor 2: 0.9110
27
+ - Auroc Sensor 2: 0.9461
28
+ - Accuracy Aggregated: 0.8822
29
+ - Auroc Aggregated: 0.9403
30
+
31
+ ## Model description
32
+
33
+ More information needed
34
+
35
+ ## Intended uses & limitations
36
+
37
+ More information needed
38
+
39
+ ## Training and evaluation data
40
+
41
+ More information needed
42
+
43
+ ## Training procedure
44
+
45
+ ### Training hyperparameters
46
+
47
+ The following hyperparameters were used during training:
48
+ - learning_rate: 2e-05
49
+ - train_batch_size: 4
50
+ - eval_batch_size: 4
51
+ - seed: 42
52
+ - gradient_accumulation_steps: 8
53
+ - total_train_batch_size: 32
54
+ - optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
55
+ - lr_scheduler_type: cosine
56
+ - lr_scheduler_warmup_steps: 64
57
+ - num_epochs: 5
58
+ - mixed_precision_training: Native AMP
59
+
60
+ ### Training results
61
+
62
+ | Training Loss | Epoch | Step | Validation Loss | Accuracy | Accuracy Sensor 0 | Auroc Sensor 0 | Accuracy Sensor 1 | Auroc Sensor 1 | Accuracy Sensor 2 | Auroc Sensor 2 | Accuracy Aggregated | Auroc Aggregated |
63
+ |:-------------:|:------:|:----:|:---------------:|:--------:|:-----------------:|:--------------:|:-----------------:|:--------------:|:-----------------:|:--------------:|:-------------------:|:----------------:|
64
+ | 0.3029 | 0.9997 | 781 | 0.5009 | 0.7947 | 0.7920 | 0.8988 | 0.7962 | 0.9030 | 0.8191 | 0.8947 | 0.7717 | 0.8803 |
65
+ | 0.2099 | 1.9994 | 1562 | 0.4386 | 0.8330 | 0.8430 | 0.9267 | 0.8214 | 0.9266 | 0.8523 | 0.9287 | 0.8154 | 0.9148 |
66
+ | 0.1366 | 2.9990 | 2343 | 0.3970 | 0.8638 | 0.8850 | 0.9499 | 0.8800 | 0.9485 | 0.8568 | 0.9428 | 0.8336 | 0.9330 |
67
+ | 0.0719 | 4.0 | 3125 | 0.3534 | 0.9090 | 0.9121 | 0.9578 | 0.9090 | 0.9575 | 0.9209 | 0.9470 | 0.8940 | 0.9424 |
68
+ | 0.0379 | 4.9984 | 3905 | 0.4759 | 0.9018 | 0.9093 | 0.9563 | 0.9046 | 0.9558 | 0.9110 | 0.9461 | 0.8822 | 0.9403 |
69
+
70
+
71
+ ### Framework versions
72
+
73
+ - Transformers 4.41.0
74
+ - Pytorch 2.3.0+cu121
75
+ - Datasets 2.19.1
76
+ - Tokenizers 0.19.1
added_tokens.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "\t\t": 50294,
3
+ "\t\t\t": 50293,
4
+ "\t\t\t\t": 50292,
5
+ "\t\t\t\t\t": 50291,
6
+ "\t\t\t\t\t\t": 50290,
7
+ "\t\t\t\t\t\t\t": 50289,
8
+ "\t\t\t\t\t\t\t\t": 50288,
9
+ "\t\t\t\t\t\t\t\t\t": 50287,
10
+ " ": 50286,
11
+ " ": 50285,
12
+ " ": 50284,
13
+ " ": 50283,
14
+ " ": 50282,
15
+ " ": 50281,
16
+ " ": 50280,
17
+ " ": 50279,
18
+ " ": 50278,
19
+ " ": 50277,
20
+ " ": 50276,
21
+ " ": 50275,
22
+ " ": 50274,
23
+ " ": 50273,
24
+ " ": 50272,
25
+ " ": 50271,
26
+ " ": 50270,
27
+ " ": 50269,
28
+ " ": 50268,
29
+ " ": 50267,
30
+ " ": 50266,
31
+ " ": 50265,
32
+ " ": 50264,
33
+ " ": 50263,
34
+ " ": 50262,
35
+ " ": 50261,
36
+ " ": 50260,
37
+ " ": 50259,
38
+ " ": 50258,
39
+ " ": 50257
40
+ }
config.json ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "Salesforce/codegen-350M-mono",
3
+ "activation_function": "gelu_new",
4
+ "aggregate_weight": 0.3,
5
+ "architectures": [
6
+ "CodeGenMeasurementPredictor"
7
+ ],
8
+ "attn_pdrop": 0.0,
9
+ "auto_map": {
10
+ "AutoConfig": "configuration_code_gen_measuremet_pred.CodeGenMeasurementPredictorConfig",
11
+ "AutoModelForSequenceClassification": "modeling_code_gen_measurement_pred.CodeGenMeasurementPredictor"
12
+ },
13
+ "bos_token_id": 1,
14
+ "emb_dim": 1024,
15
+ "embd_pdrop": 0.0,
16
+ "eos_token_id": 50256,
17
+ "gradient_checkpointing": false,
18
+ "initializer_range": 0.02,
19
+ "layer_norm_epsilon": 1e-05,
20
+ "model_type": "codegen_mp",
21
+ "n_ctx": 2048,
22
+ "n_embd": 1024,
23
+ "n_head": 16,
24
+ "n_inner": null,
25
+ "n_layer": 20,
26
+ "n_positions": 2048,
27
+ "n_sensors": 3,
28
+ "resid_pdrop": 0.0,
29
+ "rotary_dim": 32,
30
+ "scale_attn_weights": true,
31
+ "sensor_loc_type": "locs_from_token",
32
+ "sensor_token": " omit",
33
+ "sensor_token_id": 42848,
34
+ "sensors_weight": 0.7,
35
+ "summary_activation": null,
36
+ "summary_first_dropout": 0.1,
37
+ "summary_proj_to_labels": true,
38
+ "summary_type": "cls_index",
39
+ "summary_use_proj": true,
40
+ "task_specific_params": {
41
+ "text-generation": {
42
+ "do_sample": true,
43
+ "max_length": 50,
44
+ "temperature": 1.0
45
+ }
46
+ },
47
+ "tie_word_embeddings": false,
48
+ "tokenizer_class": "GPT2Tokenizer",
49
+ "torch_dtype": "float32",
50
+ "transformers_version": "4.41.0",
51
+ "use_aggregated": true,
52
+ "use_cache": false,
53
+ "vocab_size": 51200
54
+ }
configuration_code_gen_measuremet_pred.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers.models.codegen import CodeGenConfig
2
+ from .configuration_measurement_pred import MeasurementPredictorConfig
3
+
4
+ class CodeGenMeasurementPredictorConfig(MeasurementPredictorConfig, CodeGenConfig):
5
+ model_type = "codegen_mp"
6
+ def __init__(self, **kwargs):
7
+ kwargs["sensor_token_id"] = 42848
8
+ super().__init__(**kwargs)
9
+
10
+ def get_emb_dim(self):
11
+ return self.n_embd
configuration_measurement_pred.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from abc import abstractmethod
2
+ from transformers import PretrainedConfig
3
+ class MeasurementPredictorConfig(PretrainedConfig):
4
+
5
+ def __init__(
6
+ self,
7
+ sensor_token=" omit",
8
+ sensor_loc_type="locs_from_token",
9
+ n_sensors=3,
10
+ use_aggregated=True,
11
+ sensors_weight = 0.7,
12
+ aggregate_weight=0.3,
13
+ **kwargs
14
+ ):
15
+ self.sensor_token = sensor_token
16
+ self.sensor_loc_type = sensor_loc_type
17
+ self.n_sensors = n_sensors
18
+ self.use_aggregated = use_aggregated
19
+ self.sensors_weight = sensors_weight
20
+ self.aggregate_weight = aggregate_weight
21
+ super().__init__(**kwargs)
22
+ self.emb_dim = self.get_emb_dim()
23
+
24
+ @abstractmethod
25
+ def get_emb_dim(self):
26
+ raise NotImplementedError
logs/events.out.tfevents.1734404060.gail.ist.berkeley.edu.216960.0 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:72d3fdbfdf75f1684f8505966782e4885aab6457cc52b9a62799be78a0b657be
3
+ size 16069
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2eed6800bb2fdf0697d992730a4095081fcfaf6283946981189adb674638bd38
3
+ size 1216963976
modeling_code_gen_measurement_pred.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers.models.codegen import CodeGenPreTrainedModel, CodeGenModel
2
+
3
+ from .modeling_measurement_pred import MeasurementPredictorMixin
4
+ from .configuration_code_gen_measuremet_pred import CodeGenMeasurementPredictorConfig
5
+
6
+
7
+ class CodeGenMeasurementPredictor(CodeGenPreTrainedModel, MeasurementPredictorMixin):
8
+ config_class = CodeGenMeasurementPredictorConfig
9
+
10
+ def __init__(self, config):
11
+ super().__init__(config)
12
+ self.transformer = CodeGenModel(config)
13
+ self.post_init()
modeling_measurement_pred.py ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional, Tuple, Union
2
+
3
+ import torch
4
+ from torch.nn import BCEWithLogitsLoss
5
+ from transformers import PreTrainedModel, PreTrainedTokenizer
6
+ from transformers.tokenization_utils_base import PreTrainedTokenizerBase
7
+ from transformers.modeling_outputs import BaseModelOutputWithPast, SequenceClassifierOutputWithPast
8
+
9
+
10
+ from .sensor_loc_reg import SENSOR_LOC_REGISTRY
11
+ from .sensor_loc_finder import SensorLocFinder
12
+
13
+ class MeasurementPredictorMixin(PreTrainedModel):
14
+
15
+ def __init__(self, config):
16
+ super().__init__(config)
17
+ self.sensor_loc_type = config.sensor_loc_type
18
+ self.sensor_token = config.sensor_token
19
+ self.n_sensors = config.n_sensors
20
+ self.sensor_probes = torch.nn.ModuleList([
21
+ torch.nn.Linear(config.emb_dim, 1) for _ in range(config.n_sensors)
22
+ ])
23
+ self.use_aggregated = config.use_aggregated
24
+ if config.use_aggregated:
25
+ self.aggregate_probe = torch.nn.Linear(config.emb_dim, 1)
26
+ self.sensors_weight = config.sensors_weight
27
+ self.aggregate_weight = config.aggregate_weight
28
+
29
+ self.get_sensor_locs: SensorLocFinder = None
30
+
31
+ def init_sensor_loc_finder(self, tokenizer: PreTrainedTokenizerBase):
32
+ self.get_sensor_locs = SENSOR_LOC_REGISTRY[self.sensor_loc_type](
33
+ tokenizer, sensor_token=self.sensor_token, n_sensors=self.n_sensors
34
+ )
35
+
36
+ def forward(
37
+ self,
38
+ input_ids: Optional[torch.LongTensor] = None,
39
+ past_key_values: Optional[Tuple[Tuple[torch.Tensor]]] = None,
40
+ attention_mask: Optional[torch.FloatTensor] = None,
41
+ position_ids: Optional[torch.LongTensor] = None,
42
+ head_mask: Optional[torch.FloatTensor] = None,
43
+ inputs_embeds: Optional[torch.FloatTensor] = None,
44
+ labels: Optional[torch.LongTensor] = None,
45
+ use_cache: Optional[bool] = None,
46
+ output_attentions: Optional[bool] = None,
47
+ output_hidden_states: Optional[bool] = None,
48
+ return_dict: Optional[bool] = None,
49
+ ) -> Union[Tuple, SequenceClassifierOutputWithPast]:
50
+ r"""
51
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
52
+ Labels for language modeling. Note that the labels **are shifted** inside the model, i.e. you can set
53
+ `labels = input_ids` Indices are selected in `[-100, 0, ..., config.vocab_size]` All labels set to `-100`
54
+ are ignored (masked), the loss is only computed for labels in `[0, ..., config.vocab_size]`
55
+ """
56
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
57
+
58
+ base_model_output: BaseModelOutputWithPast = self.base_model(
59
+ input_ids,
60
+ past_key_values=past_key_values,
61
+ attention_mask=attention_mask,
62
+ position_ids=position_ids,
63
+ head_mask=head_mask,
64
+ inputs_embeds=inputs_embeds,
65
+ use_cache=use_cache,
66
+ output_attentions=output_attentions,
67
+ output_hidden_states=output_hidden_states,
68
+ return_dict=return_dict,
69
+ )
70
+ sensor_locs = self.get_sensor_locs(input_ids)
71
+ sensor_embs = base_model_output.last_hidden_state.gather(
72
+ 1, sensor_locs.unsqueeze(-1).expand(-1, -1, self.config.emb_dim)
73
+ )
74
+ assert sensor_embs.shape == (input_ids.shape[0], self.n_sensors, self.config.emb_dim), f"{sensor_embs.shape} != {(input_ids.shape[0], self.n_sensors, self.config.emb_dim)}"
75
+ sensor_logits = torch.concat([self.sensor_probes[i](sensor_embs[:, i, :])
76
+ for i in range(self.n_sensors)], dim=-1)
77
+ logits = sensor_logits
78
+
79
+ if self.use_aggregated:
80
+ last_emb = base_model_output.last_hidden_state[:, -1, :]
81
+ aggregate_logits = self.aggregate_probe(last_emb)
82
+ logits = torch.concat([logits, aggregate_logits], dim=-1)
83
+
84
+ loss = None
85
+ if labels is not None:
86
+ loss_fct = BCEWithLogitsLoss()
87
+ sensor_loss = loss_fct(sensor_logits, labels[:, :self.n_sensors]) * self.sensors_weight
88
+ loss = sensor_loss
89
+ if self.use_aggregated: #TOOD: should be use aggregate
90
+ aggregate_loss = loss_fct(aggregate_logits, labels[:, -1:]) * self.aggregate_weight
91
+ loss += aggregate_loss
92
+
93
+ if not return_dict:
94
+ output = (logits, ) + base_model_output[1:]
95
+ return ((loss,) + output) if loss is not None else output
96
+
97
+ return SequenceClassifierOutputWithPast(
98
+ loss=loss,
99
+ logits=logits,
100
+ past_key_values=base_model_output.past_key_values,
101
+ hidden_states=base_model_output.hidden_states,
102
+ attentions=base_model_output.attentions,
103
+ )
104
+
sensor_loc_finder.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from abc import ABC, abstractmethod
2
+ import torch
3
+ from transformers import PreTrainedTokenizerBase
4
+
5
+
6
+ class SensorLocFinder(ABC):
7
+
8
+ @abstractmethod
9
+ def __init__(self, tokenizer: PreTrainedTokenizerBase, **kwargs):
10
+ pass
11
+
12
+ @abstractmethod
13
+ def find_sensor_locs(self, input_ids: torch.Tensor) -> torch.Tensor:
14
+ pass
15
+
16
+ def __call__(self, input_ids: torch.Tensor) -> torch.Tensor:
17
+ return self.find_sensor_locs(input_ids)
sensor_loc_reg.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ from enum import Enum
2
+
3
+ from .sensor_loc_stories import StoriesSensorLocFinder
4
+ from .sensor_locs_from_token import SensorLocFinderFromToken
5
+
6
+
7
+ SENSOR_LOC_REGISTRY = {
8
+ "stories": StoriesSensorLocFinder,
9
+ "locs_from_token": SensorLocFinderFromToken
10
+ }
sensor_loc_stories.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import PreTrainedTokenizerBase
3
+
4
+ from .sensor_loc_finder import SensorLocFinder
5
+
6
+
7
+ class StoriesSensorLocFinder(SensorLocFinder):
8
+
9
+ def __init__(self, tokenizer: PreTrainedTokenizerBase, **kwargs):
10
+ self.questions_section_toks = tokenizer.encode("## Questions")
11
+ self.question_mark_tok = tokenizer.encode("?")[0]
12
+ self.other_question_mark_tok = tokenizer.encode(")?")[0]
13
+ assert len(self.questions_section_toks) == 2
14
+
15
+ def find_sensor_locs(self, input_ids: torch.Tensor) -> torch.Tensor:
16
+ device = input_ids.device
17
+ question_mark_locs = self._is_sensor_loc(input_ids)
18
+ total_locs = torch.cumsum(question_mark_locs, dim=-1)
19
+ total_overall = total_locs[:, -1]
20
+ assert (
21
+ total_overall == 3
22
+ ).all(), "can handle different cases, but assuming this is easiest"
23
+ eqs = total_locs[:, :, None] == torch.arange(1, 4)[None, None].to(device)
24
+ locs = torch.where(
25
+ eqs.any(dim=-2),
26
+ torch.argmax(eqs.to(torch.uint8), dim=-2),
27
+ input_ids.shape[-1] - 3,
28
+ ).clamp(max=input_ids.shape[-1] - 3)
29
+ return locs
30
+
31
+
32
+ def _is_sensor_loc(self, input_ids: torch.Tensor):
33
+ questions_section_toks = self.questions_section_toks
34
+ question_mark_tok = self.question_mark_tok
35
+ other_question_mark_tok = self.other_question_mark_tok
36
+ eq_question_item = (input_ids[:, :-1] == questions_section_toks[0]) & (
37
+ input_ids[:, 1:] == questions_section_toks[1]
38
+ )
39
+ assert (eq_question_item.sum(dim=-1, dtype=torch.int) == 1).all(), "could relax"
40
+
41
+ summed = torch.cumsum(
42
+ torch.cat([eq_question_item, eq_question_item[:, -1:]], dim=-1), dim=-1
43
+ )
44
+ return (summed > 0) & (
45
+ (input_ids == question_mark_tok) | (input_ids == other_question_mark_tok)
46
+ )
sensor_locs_from_token.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import PreTrainedTokenizerBase
3
+
4
+ from .sensor_loc_finder import SensorLocFinder
5
+
6
+
7
+ class SensorLocFinderFromToken(SensorLocFinder):
8
+
9
+ def __init__(self, tokenizer: PreTrainedTokenizerBase, sensor_token: str, n_sensors: int):
10
+ self.sensor_token_id = tokenizer.encode(sensor_token)[0]
11
+ self.n_sensors = n_sensors
12
+
13
+ def find_sensor_locs(self, input_ids: torch.Tensor) -> torch.Tensor:
14
+ flat_sensor_token_idxs = (input_ids == self.sensor_token_id).nonzero(as_tuple=True)[1]
15
+ sensor_token_idxs = flat_sensor_token_idxs.view(-1, self.n_sensors)
16
+ return sensor_token_idxs
special_tokens_map.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<|endoftext|>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "<|endoftext|>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": "<|endoftext|>",
17
+ "unk_token": {
18
+ "content": "<|endoftext|>",
19
+ "lstrip": false,
20
+ "normalized": false,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ }
24
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,327 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "added_tokens_decoder": {
4
+ "50256": {
5
+ "content": "<|endoftext|>",
6
+ "lstrip": false,
7
+ "normalized": false,
8
+ "rstrip": false,
9
+ "single_word": false,
10
+ "special": true
11
+ },
12
+ "50257": {
13
+ "content": " ",
14
+ "lstrip": false,
15
+ "normalized": true,
16
+ "rstrip": false,
17
+ "single_word": false,
18
+ "special": false
19
+ },
20
+ "50258": {
21
+ "content": " ",
22
+ "lstrip": false,
23
+ "normalized": true,
24
+ "rstrip": false,
25
+ "single_word": false,
26
+ "special": false
27
+ },
28
+ "50259": {
29
+ "content": " ",
30
+ "lstrip": false,
31
+ "normalized": true,
32
+ "rstrip": false,
33
+ "single_word": false,
34
+ "special": false
35
+ },
36
+ "50260": {
37
+ "content": " ",
38
+ "lstrip": false,
39
+ "normalized": true,
40
+ "rstrip": false,
41
+ "single_word": false,
42
+ "special": false
43
+ },
44
+ "50261": {
45
+ "content": " ",
46
+ "lstrip": false,
47
+ "normalized": true,
48
+ "rstrip": false,
49
+ "single_word": false,
50
+ "special": false
51
+ },
52
+ "50262": {
53
+ "content": " ",
54
+ "lstrip": false,
55
+ "normalized": true,
56
+ "rstrip": false,
57
+ "single_word": false,
58
+ "special": false
59
+ },
60
+ "50263": {
61
+ "content": " ",
62
+ "lstrip": false,
63
+ "normalized": true,
64
+ "rstrip": false,
65
+ "single_word": false,
66
+ "special": false
67
+ },
68
+ "50264": {
69
+ "content": " ",
70
+ "lstrip": false,
71
+ "normalized": true,
72
+ "rstrip": false,
73
+ "single_word": false,
74
+ "special": false
75
+ },
76
+ "50265": {
77
+ "content": " ",
78
+ "lstrip": false,
79
+ "normalized": true,
80
+ "rstrip": false,
81
+ "single_word": false,
82
+ "special": false
83
+ },
84
+ "50266": {
85
+ "content": " ",
86
+ "lstrip": false,
87
+ "normalized": true,
88
+ "rstrip": false,
89
+ "single_word": false,
90
+ "special": false
91
+ },
92
+ "50267": {
93
+ "content": " ",
94
+ "lstrip": false,
95
+ "normalized": true,
96
+ "rstrip": false,
97
+ "single_word": false,
98
+ "special": false
99
+ },
100
+ "50268": {
101
+ "content": " ",
102
+ "lstrip": false,
103
+ "normalized": true,
104
+ "rstrip": false,
105
+ "single_word": false,
106
+ "special": false
107
+ },
108
+ "50269": {
109
+ "content": " ",
110
+ "lstrip": false,
111
+ "normalized": true,
112
+ "rstrip": false,
113
+ "single_word": false,
114
+ "special": false
115
+ },
116
+ "50270": {
117
+ "content": " ",
118
+ "lstrip": false,
119
+ "normalized": true,
120
+ "rstrip": false,
121
+ "single_word": false,
122
+ "special": false
123
+ },
124
+ "50271": {
125
+ "content": " ",
126
+ "lstrip": false,
127
+ "normalized": true,
128
+ "rstrip": false,
129
+ "single_word": false,
130
+ "special": false
131
+ },
132
+ "50272": {
133
+ "content": " ",
134
+ "lstrip": false,
135
+ "normalized": true,
136
+ "rstrip": false,
137
+ "single_word": false,
138
+ "special": false
139
+ },
140
+ "50273": {
141
+ "content": " ",
142
+ "lstrip": false,
143
+ "normalized": true,
144
+ "rstrip": false,
145
+ "single_word": false,
146
+ "special": false
147
+ },
148
+ "50274": {
149
+ "content": " ",
150
+ "lstrip": false,
151
+ "normalized": true,
152
+ "rstrip": false,
153
+ "single_word": false,
154
+ "special": false
155
+ },
156
+ "50275": {
157
+ "content": " ",
158
+ "lstrip": false,
159
+ "normalized": true,
160
+ "rstrip": false,
161
+ "single_word": false,
162
+ "special": false
163
+ },
164
+ "50276": {
165
+ "content": " ",
166
+ "lstrip": false,
167
+ "normalized": true,
168
+ "rstrip": false,
169
+ "single_word": false,
170
+ "special": false
171
+ },
172
+ "50277": {
173
+ "content": " ",
174
+ "lstrip": false,
175
+ "normalized": true,
176
+ "rstrip": false,
177
+ "single_word": false,
178
+ "special": false
179
+ },
180
+ "50278": {
181
+ "content": " ",
182
+ "lstrip": false,
183
+ "normalized": true,
184
+ "rstrip": false,
185
+ "single_word": false,
186
+ "special": false
187
+ },
188
+ "50279": {
189
+ "content": " ",
190
+ "lstrip": false,
191
+ "normalized": true,
192
+ "rstrip": false,
193
+ "single_word": false,
194
+ "special": false
195
+ },
196
+ "50280": {
197
+ "content": " ",
198
+ "lstrip": false,
199
+ "normalized": true,
200
+ "rstrip": false,
201
+ "single_word": false,
202
+ "special": false
203
+ },
204
+ "50281": {
205
+ "content": " ",
206
+ "lstrip": false,
207
+ "normalized": true,
208
+ "rstrip": false,
209
+ "single_word": false,
210
+ "special": false
211
+ },
212
+ "50282": {
213
+ "content": " ",
214
+ "lstrip": false,
215
+ "normalized": true,
216
+ "rstrip": false,
217
+ "single_word": false,
218
+ "special": false
219
+ },
220
+ "50283": {
221
+ "content": " ",
222
+ "lstrip": false,
223
+ "normalized": true,
224
+ "rstrip": false,
225
+ "single_word": false,
226
+ "special": false
227
+ },
228
+ "50284": {
229
+ "content": " ",
230
+ "lstrip": false,
231
+ "normalized": true,
232
+ "rstrip": false,
233
+ "single_word": false,
234
+ "special": false
235
+ },
236
+ "50285": {
237
+ "content": " ",
238
+ "lstrip": false,
239
+ "normalized": true,
240
+ "rstrip": false,
241
+ "single_word": false,
242
+ "special": false
243
+ },
244
+ "50286": {
245
+ "content": " ",
246
+ "lstrip": false,
247
+ "normalized": true,
248
+ "rstrip": false,
249
+ "single_word": false,
250
+ "special": false
251
+ },
252
+ "50287": {
253
+ "content": "\t\t\t\t\t\t\t\t\t",
254
+ "lstrip": false,
255
+ "normalized": true,
256
+ "rstrip": false,
257
+ "single_word": false,
258
+ "special": false
259
+ },
260
+ "50288": {
261
+ "content": "\t\t\t\t\t\t\t\t",
262
+ "lstrip": false,
263
+ "normalized": true,
264
+ "rstrip": false,
265
+ "single_word": false,
266
+ "special": false
267
+ },
268
+ "50289": {
269
+ "content": "\t\t\t\t\t\t\t",
270
+ "lstrip": false,
271
+ "normalized": true,
272
+ "rstrip": false,
273
+ "single_word": false,
274
+ "special": false
275
+ },
276
+ "50290": {
277
+ "content": "\t\t\t\t\t\t",
278
+ "lstrip": false,
279
+ "normalized": true,
280
+ "rstrip": false,
281
+ "single_word": false,
282
+ "special": false
283
+ },
284
+ "50291": {
285
+ "content": "\t\t\t\t\t",
286
+ "lstrip": false,
287
+ "normalized": true,
288
+ "rstrip": false,
289
+ "single_word": false,
290
+ "special": false
291
+ },
292
+ "50292": {
293
+ "content": "\t\t\t\t",
294
+ "lstrip": false,
295
+ "normalized": true,
296
+ "rstrip": false,
297
+ "single_word": false,
298
+ "special": false
299
+ },
300
+ "50293": {
301
+ "content": "\t\t\t",
302
+ "lstrip": false,
303
+ "normalized": true,
304
+ "rstrip": false,
305
+ "single_word": false,
306
+ "special": false
307
+ },
308
+ "50294": {
309
+ "content": "\t\t",
310
+ "lstrip": false,
311
+ "normalized": true,
312
+ "rstrip": false,
313
+ "single_word": false,
314
+ "special": false
315
+ }
316
+ },
317
+ "bos_token": "<|endoftext|>",
318
+ "clean_up_tokenization_spaces": true,
319
+ "eos_token": "<|endoftext|>",
320
+ "model_max_length": 2048,
321
+ "pad_token": "<|endoftext|>",
322
+ "padding_side": "left",
323
+ "return_token_type_ids": false,
324
+ "tokenizer_class": "CodeGenTokenizer",
325
+ "truncation_side": "left",
326
+ "unk_token": "<|endoftext|>"
327
+ }
train.log ADDED
@@ -0,0 +1 @@
 
 
1
+ [2024-12-16 18:54:19,529][accelerate.utils.other][WARNING] - Detected kernel version 5.4.0, which is below the recommended minimum of 5.5.0; this can cause the process to hang. It is recommended to upgrade the kernel to the minimum version or higher.
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7e934d182467e275d01e51caa2e9e2886c0a9d04fa2b3d568b2fbe78aa009f50
3
+ size 5112
vocab.json ADDED
The diff for this file is too large to render. See raw diff