Inference API
swebench.inference
llamao
distributed_attention
SeqAllToAll
Bases: Function
forward
staticmethod
forward(ctx: Any, input: Tensor, scatter_idx: int, gather_idx: int, group: Any) -> Tensor
Source code in swebench/inference/llamao/distributed_attention.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
backward
staticmethod
backward(ctx: Any, *grad_output: Tensor) -> tuple[Tensor, None, None, None]
Source code in swebench/inference/llamao/distributed_attention.py
34 35 36 37 38 39 40 41 |
|
DistributedAttention
DistributedAttention(local_attention: Module, scatter_idx: int = -2, gather_idx: int = 1)
Bases: Module
Initialization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
local_attention
|
Module
|
local attention with q,k,v |
required |
scatter_idx
|
int
|
scatter_idx for all2all comm |
-2
|
gather_idx
|
int
|
gather_idx for all2all comm |
1
|
Source code in swebench/inference/llamao/distributed_attention.py
53 54 55 56 57 58 59 60 61 62 |
|
local_attn
instance-attribute
local_attn = local_attention
scatter_idx
instance-attribute
scatter_idx = scatter_idx
gather_idx
instance-attribute
gather_idx = gather_idx
forward
forward(query: Tensor, key_values: Tensor, group: Any = None, **kwargs) -> Tensor
forward
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
Tensor
|
query input to the layer |
required |
key
|
Tensor
|
key input to the layer |
required |
value
|
Tensor
|
value input to the layer |
required |
args
|
other args |
required |
Returns:
Type | Description |
---|---|
Tensor
|
|
Source code in swebench/inference/llamao/distributed_attention.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
modeling_flash_llama
PyTorch LLaMA model.
logger
module-attribute
logger = get_logger(__name__)
LlamaRMSNorm
LlamaRMSNorm(hidden_size, eps=1e-06)
Bases: Module
LlamaRMSNorm is equivalent to T5LayerNorm
Source code in swebench/inference/llamao/modeling_flash_llama.py
66 67 68 69 70 71 72 73 74 75 76 |
|
weight
instance-attribute
weight = Parameter(ones(hidden_size))
forward
forward(hidden_states)
Source code in swebench/inference/llamao/modeling_flash_llama.py
78 79 |
|
FlashRotaryEmbedding
FlashRotaryEmbedding(dim: int, base=10000.0, interleaved=False, scale_base=None, scaling_factor=1.0, pos_idx_in_fp32=True, device=None)
Bases: Module
The rotary position embeddings from RoFormer_ (Su et. al). A crucial insight from the method is that the query and keys are transformed by rotation matrices which depend on the relative positions.
Other implementations are available in the Rotary Transformer repo_ and in GPT-NeoX_, GPT-NeoX was an inspiration
.. _RoFormer: https://arxiv.org/abs/2104.09864 .. _repo: https://github.com/ZhuiyiTechnology/roformer .. _GPT-NeoX: https://github.com/EleutherAI/gpt-neox
If scale_base is not None, this implements XPos (Sun et al., https://arxiv.org/abs/2212.10554). A recommended value for scale_base is 512: https://github.com/HazyResearch/flash-attention/issues/96 Reference: https://github.com/sunyt32/torchscale/blob/main/torchscale/component/xpos_relative_position.py
if True, rotate pairs of even and odd dimensions (GPT-J style) instead
of 1st half and 2nd half (GPT-NeoX style).
pos_idx_in_fp32: if True, the position indices [0.0, ..., seqlen - 1] are in fp32, otherwise they might be in lower precision. This option was added because previously (before 2023-07-02), when we construct the position indices, we use the dtype of self.inv_freq. In most cases this would be fp32, but if the model is trained in pure bf16 (not mixed precision), then self.inv_freq would be bf16, and the position indices are also in bf16. Because of the limited precision of bf16 (e.g. 1995.0 is rounded to 2000.0), the embeddings for some positions will coincide. To maintain compatibility with models previously trained in pure bf16, we add this option. scaling_factor: RotaryEmbedding extended with linear scaling.
Source code in swebench/inference/llamao/modeling_flash_llama.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
dim
instance-attribute
dim = dim
base
instance-attribute
base = float(base)
pos_idx_in_fp32
instance-attribute
pos_idx_in_fp32 = pos_idx_in_fp32
interleaved
instance-attribute
interleaved = interleaved
scale_base
instance-attribute
scale_base = scale_base
scaling_factor
instance-attribute
scaling_factor = scaling_factor
forward
forward(q: Tensor, k: Tensor, seqlen_offset: int = 0, unpadded_lengths: Optional[tuple[Tensor]] = None) -> tuple[Tensor, Tensor]
q: (batch, seqlen, nheads, headdim) k: (batch, seqlen, nheads, headdim) seqlen_offset: can be used in generation where the qkv being passed in is only the last token in the batch.
Source code in swebench/inference/llamao/modeling_flash_llama.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|
LlamaMLP
LlamaMLP(config)
Bases: Module
Source code in swebench/inference/llamao/modeling_flash_llama.py
254 255 256 257 258 259 260 261 262 |
|
config
instance-attribute
config = config
hidden_size = hidden_size
intermediate_size
instance-attribute
intermediate_size = intermediate_size
gate_proj
instance-attribute
gate_proj = Linear(hidden_size, intermediate_size, bias=False)
up_proj
instance-attribute
up_proj = Linear(hidden_size, intermediate_size, bias=False)
down_proj
instance-attribute
down_proj = Linear(intermediate_size, hidden_size, bias=False)
act_fn
instance-attribute
act_fn = ACT2FN[hidden_act]
forward
forward(x)
Source code in swebench/inference/llamao/modeling_flash_llama.py
264 265 |
|
LlamaAttention
LlamaAttention(config: LlamaConfig)
Bases: Module
Multi-headed attention from 'Attention Is All You Need' paper
Source code in swebench/inference/llamao/modeling_flash_llama.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
|
config
instance-attribute
config = config
hidden_size = hidden_size
num_heads
instance-attribute
num_heads = num_attention_heads
head_dim
instance-attribute
head_dim = hidden_size // num_heads
num_key_value_heads
instance-attribute
num_key_value_heads = getattr(config, 'num_key_value_heads', num_heads)
num_key_value_groups
instance-attribute
num_key_value_groups = num_heads // num_key_value_heads
max_position_embeddings
instance-attribute
max_position_embeddings = max_position_embeddings
q_proj
instance-attribute
q_proj = Linear(hidden_size, num_heads * head_dim, bias=False)
k_proj
instance-attribute
k_proj = Linear(hidden_size, num_key_value_heads * head_dim, bias=False)
v_proj
instance-attribute
v_proj = Linear(hidden_size, num_key_value_heads * head_dim, bias=False)
o_proj
instance-attribute
o_proj = Linear(num_heads * head_dim, hidden_size, bias=False)
rotary_emb
instance-attribute
rotary_emb = FlashRotaryEmbedding(head_dim, base=theta, interleaved=False, scaling_factor=scaling_factor)
distributed_attn_func
instance-attribute
distributed_attn_func = DistributedAttention(flash_attn_kvpacked_func)
forward
forward(hidden_states: Tensor, attention_mask: Optional[Tensor] = None, position_ids: Optional[LongTensor] = None, past_key_value: Optional[tuple[Tensor]] = None, output_attentions: bool = False, use_cache: bool = False, unpadded_lengths: Optional[tuple[Tensor]] = None, seq_parallel_group: Optional[Any] = None) -> tuple[Tensor, Optional[Tensor], Optional[tuple[Tensor]]]
Source code in swebench/inference/llamao/modeling_flash_llama.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
|
LlamaDecoderLayer
LlamaDecoderLayer(config: LlamaConfig)
Bases: Module
Source code in swebench/inference/llamao/modeling_flash_llama.py
463 464 465 466 467 468 469 470 471 472 |
|
hidden_size = hidden_size
post_attention_layernorm
instance-attribute
post_attention_layernorm = LlamaRMSNorm(hidden_size, eps=rms_norm_eps)
forward
forward(hidden_states: Tensor, attention_mask: Optional[Tensor] = None, position_ids: Optional[LongTensor] = None, past_key_value: Optional[tuple[Tensor]] = None, unpadded_lengths: Optional[tuple[Tensor]] = None, output_attentions: Optional[bool] = False, use_cache: Optional[bool] = False, seq_parallel_group: Optional[Any] = None) -> tuple[FloatTensor, Optional[tuple[FloatTensor, FloatTensor]]]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hidden_states
|
`torch.FloatTensor`
|
input to the layer of shape |
required |
attention_mask
|
`torch.FloatTensor`, *optional*
|
attention mask of size
|
None
|
output_attentions
|
`bool`, *optional*
|
Whether or not to return the attentions tensors of all attention layers. See |
False
|
use_cache
|
`bool`, *optional*
|
If set to |
False
|
past_key_value
|
`Tuple(torch.FloatTensor)`, *optional*
|
cached past key and value projection states |
None
|
Source code in swebench/inference/llamao/modeling_flash_llama.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 |
|
LlamaPreTrainedModel
Bases: PreTrainedModel
config_class
class-attribute
instance-attribute
config_class = LlamaConfig
base_model_prefix
class-attribute
instance-attribute
base_model_prefix = 'model'
supports_gradient_checkpointing
class-attribute
instance-attribute
supports_gradient_checkpointing = True
LlamaModel
LlamaModel(config: LlamaConfig)
Bases: LlamaPreTrainedModel
Transformer decoder consisting of config.num_hidden_layers layers. Each layer is a [LlamaDecoderLayer
]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
LlamaConfig
|
LlamaConfig |
required |
Source code in swebench/inference/llamao/modeling_flash_llama.py
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 |
|
padding_idx
instance-attribute
padding_idx = pad_token_id
vocab_size
instance-attribute
vocab_size = vocab_size
embed_tokens
instance-attribute
embed_tokens = Embedding(vocab_size, hidden_size, padding_idx)
layers
instance-attribute
layers = ModuleList([LlamaDecoderLayer(config) for _ in range(num_hidden_layers)])
gradient_checkpointing
instance-attribute
gradient_checkpointing = False
get_input_embeddings
get_input_embeddings()
Source code in swebench/inference/llamao/modeling_flash_llama.py
583 584 |
|
set_input_embeddings
set_input_embeddings(value)
Source code in swebench/inference/llamao/modeling_flash_llama.py
586 587 |
|
forward
forward(input_ids: LongTensor = None, attention_mask: Optional[Tensor] = None, position_ids: Optional[LongTensor] = None, past_key_values: Optional[list[FloatTensor]] = None, inputs_embeds: Optional[FloatTensor] = None, use_cache: Optional[bool] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, seq_parallel_group: Optional[Any] = None) -> Union[tuple, BaseModelOutputWithPast]
Source code in swebench/inference/llamao/modeling_flash_llama.py
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 |
|
LlamaForCausalLM
LlamaForCausalLM(config)
Bases: LlamaPreTrainedModel
Source code in swebench/inference/llamao/modeling_flash_llama.py
737 738 739 740 741 742 743 744 |
|
vocab_size
instance-attribute
vocab_size = vocab_size
lm_head
instance-attribute
lm_head = Linear(hidden_size, vocab_size, bias=False)
get_input_embeddings
get_input_embeddings()
Source code in swebench/inference/llamao/modeling_flash_llama.py
746 747 |
|
set_input_embeddings
set_input_embeddings(value)
Source code in swebench/inference/llamao/modeling_flash_llama.py
749 750 |
|
get_output_embeddings
get_output_embeddings()
Source code in swebench/inference/llamao/modeling_flash_llama.py
752 753 |
|
set_output_embeddings
set_output_embeddings(new_embeddings)
Source code in swebench/inference/llamao/modeling_flash_llama.py
755 756 |
|
set_decoder
set_decoder(decoder)
Source code in swebench/inference/llamao/modeling_flash_llama.py
758 759 |
|
get_decoder
get_decoder()
Source code in swebench/inference/llamao/modeling_flash_llama.py
761 762 |
|
forward
forward(input_ids: LongTensor = None, attention_mask: Optional[Tensor] = None, position_ids: Optional[LongTensor] = None, past_key_values: Optional[list[FloatTensor]] = None, inputs_embeds: Optional[FloatTensor] = None, labels: Optional[LongTensor] = None, use_cache: Optional[bool] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None, unpadded_lengths: Optional[bool] = None, avg_valid_labels_per_chunk: Optional[float] = None, seq_parallel_group: Optional[Any] = None) -> Union[tuple, CausalLMOutputWithPast]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
labels
|
`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*
|
Labels for computing the masked language modeling loss. Indices should either be in |
None
|
Returns:
Example:
>>> from transformers import AutoTokenizer, LlamaForCausalLM
>>> model = LlamaForCausalLM.from_pretrained(PATH_TO_CONVERTED_WEIGHTS)
>>> tokenizer = AutoTokenizer.from_pretrained(PATH_TO_CONVERTED_TOKENIZER)
>>> prompt = "Hey, are you conscious? Can you talk to me?"
>>> inputs = tokenizer(prompt, return_tensors="pt")
>>> # Generate
>>> generate_ids = model.generate(inputs.input_ids, max_length=30)
>>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
"Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
Source code in swebench/inference/llamao/modeling_flash_llama.py
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 |
|
prepare_inputs_for_generation
prepare_inputs_for_generation(input_ids, past_key_values=None, attention_mask=None, inputs_embeds=None, **kwargs)
Source code in swebench/inference/llamao/modeling_flash_llama.py
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 |
|
LlamaForSequenceClassification
LlamaForSequenceClassification(config)
Bases: LlamaPreTrainedModel
Source code in swebench/inference/llamao/modeling_flash_llama.py
917 918 919 920 921 922 923 924 |
|
num_labels
instance-attribute
num_labels = num_labels
score
instance-attribute
score = Linear(hidden_size, num_labels, bias=False)
get_input_embeddings
get_input_embeddings()
Source code in swebench/inference/llamao/modeling_flash_llama.py
926 927 |
|
set_input_embeddings
set_input_embeddings(value)
Source code in swebench/inference/llamao/modeling_flash_llama.py
929 930 |
|
forward
forward(input_ids: LongTensor = None, attention_mask: Optional[Tensor] = None, position_ids: Optional[LongTensor] = None, past_key_values: Optional[list[FloatTensor]] = None, inputs_embeds: Optional[FloatTensor] = None, labels: Optional[LongTensor] = None, use_cache: Optional[bool] = None, output_attentions: Optional[bool] = None, output_hidden_states: Optional[bool] = None, return_dict: Optional[bool] = None) -> Union[tuple, SequenceClassifierOutputWithPast]
labels (torch.LongTensor
of shape (batch_size,)
, optional):
Labels for computing the sequence classification/regression loss. Indices should be in [0, ...,
config.num_labels - 1]
. If config.num_labels == 1
a regression loss is computed (Mean-Square loss), If
config.num_labels > 1
a classification loss is computed (Cross-Entropy).
Source code in swebench/inference/llamao/modeling_flash_llama.py
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 |
|
rmsnorm_func
rmsnorm_func(hidden_states, weight, variance_epsilon)
Source code in swebench/inference/llamao/modeling_flash_llama.py
57 58 59 60 61 62 |
|
repeat_kv
repeat_kv(hidden_states: Tensor, n_rep: int) -> Tensor
This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch, num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
Source code in swebench/inference/llamao/modeling_flash_llama.py
268 269 270 271 272 273 274 275 276 277 278 279 |
|
make_datasets
bm25_retrieval
logger
module-attribute
logger = getLogger(__name__)
DOCUMENT_ENCODING_FUNCTIONS
module-attribute
DOCUMENT_ENCODING_FUNCTIONS = {'file_name_and_contents': file_name_and_contents, 'file_name_and_documentation': file_name_and_documentation, 'file_name_and_docs_jedi': file_name_and_docs_jedi}
parser
module-attribute
parser = ArgumentParser()
args
module-attribute
args = parse_args()
ContextManager
ContextManager(repo_path, base_commit, verbose=False)
A context manager for managing a Git repository at a specific commit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo_path
|
str
|
The path to the Git repository. |
required |
base_commit
|
str
|
The commit hash to switch to. |
required |
verbose
|
bool
|
Whether to print verbose output. Defaults to False. |
False
|
Attributes:
Name | Type | Description |
---|---|---|
repo_path |
str
|
The path to the Git repository. |
base_commit |
str
|
The commit hash to switch to. |
verbose |
bool
|
Whether to print verbose output. |
repo |
Repo
|
The Git repository object. |
Methods:
Name | Description |
---|---|
__enter__ |
Switches to the specified commit and returns the context manager object. |
get_readme_files |
Returns a list of filenames for all README files in the repository. |
__exit__ |
Does nothing. |
Source code in swebench/inference/make_datasets/bm25_retrieval.py
46 47 48 49 50 |
|
repo_path
instance-attribute
repo_path = as_posix()
base_commit
instance-attribute
base_commit = base_commit
verbose
instance-attribute
verbose = verbose
repo
instance-attribute
repo = Repo(repo_path)
__enter__
__enter__()
Source code in swebench/inference/make_datasets/bm25_retrieval.py
52 53 54 55 56 57 58 59 60 61 62 |
|
get_readme_files
get_readme_files()
Source code in swebench/inference/make_datasets/bm25_retrieval.py
64 65 66 67 68 |
|
__exit__
__exit__(exc_type, exc_val, exc_tb)
Source code in swebench/inference/make_datasets/bm25_retrieval.py
70 71 |
|
file_name_and_contents
file_name_and_contents(filename, relative_path)
Source code in swebench/inference/make_datasets/bm25_retrieval.py
74 75 76 77 78 |
|
file_name_and_documentation
file_name_and_documentation(filename, relative_path)
Source code in swebench/inference/make_datasets/bm25_retrieval.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
|
file_name_and_docs_jedi
file_name_and_docs_jedi(filename, relative_path)
Source code in swebench/inference/make_datasets/bm25_retrieval.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
clone_repo
clone_repo(repo, root_dir, token)
Clones a GitHub repository to a specified directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo
|
str
|
The GitHub repository to clone. |
required |
root_dir
|
str
|
The root directory to clone the repository to. |
required |
token
|
str
|
The GitHub personal access token to use for authentication. |
required |
Returns:
Name | Type | Description |
---|---|---|
Path |
The path to the cloned repository directory. |
Source code in swebench/inference/make_datasets/bm25_retrieval.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
build_documents
build_documents(repo_dir, commit, document_encoding_func)
Builds a dictionary of documents from a given repository directory and commit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo_dir
|
str
|
The path to the repository directory. |
required |
commit
|
str
|
The commit hash to use. |
required |
document_encoding_func
|
function
|
A function that takes a filename and a relative path and returns the encoded document text. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
A dictionary where the keys are the relative paths of the documents and the values are the encoded document text. |
Source code in swebench/inference/make_datasets/bm25_retrieval.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
make_index
make_index(repo_dir, root_dir, query, commit, document_encoding_func, python, instance_id)
Builds an index for a given set of documents using Pyserini.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo_dir
|
str
|
The path to the repository directory. |
required |
root_dir
|
str
|
The path to the root directory. |
required |
query
|
str
|
The query to use for retrieval. |
required |
commit
|
str
|
The commit hash to use for retrieval. |
required |
document_encoding_func
|
function
|
The function to use for encoding documents. |
required |
python
|
str
|
The path to the Python executable. |
required |
instance_id
|
int
|
The ID of the current instance. |
required |
Returns:
Name | Type | Description |
---|---|---|
index_path |
Path
|
The path to the built index. |
Source code in swebench/inference/make_datasets/bm25_retrieval.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
get_remaining_instances
get_remaining_instances(instances, output_file)
Filters a list of instances to exclude those that have already been processed and saved in a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instances
|
List[Dict]
|
A list of instances, where each instance is a dictionary with an "instance_id" key. |
required |
output_file
|
Path
|
The path to the file where the processed instances are saved. |
required |
Returns:
Type | Description |
---|---|
List[Dict]: A list of instances that have not been processed yet. |
Source code in swebench/inference/make_datasets/bm25_retrieval.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
|
search
search(instance, index_path)
Searches for relevant documents in the given index for the given instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instance
|
dict
|
The instance to search for. |
required |
index_path
|
str
|
The path to the index to search in. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
A dictionary containing the instance ID and a list of hits, where each hit is a dictionary containing the |
|
document ID and its score. |
Source code in swebench/inference/make_datasets/bm25_retrieval.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 |
|
search_indexes
search_indexes(remaining_instance, output_file, all_index_paths)
Searches the indexes for the given instances and writes the results to the output file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
remaining_instance
|
list
|
A list of instances to search for. |
required |
output_file
|
str
|
The path to the output file to write the results to. |
required |
all_index_paths
|
dict
|
A dictionary mapping instance IDs to the paths of their indexes. |
required |
Source code in swebench/inference/make_datasets/bm25_retrieval.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
|
get_missing_ids
get_missing_ids(instances, output_file)
Source code in swebench/inference/make_datasets/bm25_retrieval.py
371 372 373 374 375 376 377 378 379 380 381 382 383 |
|
get_index_paths_worker
get_index_paths_worker(instance, root_dir_name, document_encoding_func, python, token)
Source code in swebench/inference/make_datasets/bm25_retrieval.py
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
|
get_index_paths
get_index_paths(remaining_instances: list[dict[str, Any]], root_dir_name: str, document_encoding_func: Any, python: str, token: str, output_file: str) -> dict[str, str]
Retrieves the index paths for the given instances using multiple processes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
remaining_instances
|
list[dict[str, Any]]
|
A list of instances for which to retrieve the index paths. |
required |
root_dir_name
|
str
|
The root directory name. |
required |
document_encoding_func
|
Any
|
A function for encoding documents. |
required |
python
|
str
|
The path to the Python executable. |
required |
token
|
str
|
The token to use for authentication. |
required |
output_file
|
str
|
The output file. |
required |
num_workers
|
The number of worker processes to use. |
required |
Returns:
Type | Description |
---|---|
dict[str, str]
|
A dictionary mapping instance IDs to index paths. |
Source code in swebench/inference/make_datasets/bm25_retrieval.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
|
get_root_dir
get_root_dir(dataset_name, output_dir, document_encoding_style)
Source code in swebench/inference/make_datasets/bm25_retrieval.py
453 454 455 456 457 458 |
|
main
main(dataset_name_or_path, document_encoding_style, output_dir, shard_id, num_shards, splits, leave_indexes)
Source code in swebench/inference/make_datasets/bm25_retrieval.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
|
create_instance
logger
module-attribute
logger = getLogger(__name__)
PATCH_EXAMPLE
module-attribute
PATCH_EXAMPLE = '--- a/file.py\n+++ b/file.py\n@@ -1,27 +1,35 @@\n def euclidean(a, b):\n- while b:\n- a, b = b, a % b\n- return a\n+ if b == 0:\n+ return a\n+ return euclidean(b, a % b)\n \n \n def bresenham(x0, y0, x1, y1):\n points = []\n dx = abs(x1 - x0)\n dy = abs(y1 - y0)\n- sx = 1 if x0 < x1 else -1\n- sy = 1 if y0 < y1 else -1\n- err = dx - dy\n+ x, y = x0, y0\n+ sx = -1 if x0 > x1 else 1\n+ sy = -1 if y0 > y1 else 1\n \n- while True:\n- points.append((x0, y0))\n- if x0 == x1 and y0 == y1:\n- break\n- e2 = 2 * err\n- if e2 > -dy:\n+ if dx > dy:\n+ err = dx / 2.0\n+ while x != x1:\n+ points.append((x, y))\n err -= dy\n- x0 += sx\n- if e2 < dx:\n- err += dx\n- y0 += sy\n+ if err < 0:\n+ y += sy\n+ err += dx\n+ x += sx\n+ else:\n+ err = dy / 2.0\n+ while y != y1:\n+ points.append((x, y))\n+ err -= dx\n+ if err < 0:\n+ x += sx\n+ err += dy\n+ y += sy\n \n+ points.append((x, y))\n return points'
FULL_GENERATION_EXAMPLE
module-attribute
FULL_GENERATION_EXAMPLE = '[start of /src/this_file.py]\nimport os\n\ndef euclidean(a, b):\n if b == 0:\n return a\n return euclidean(b, a % b)\n[end of /src/this_file.py]\n[start of /src/another_file.py]\ndef bresenham(x0, y0, x1, y1):\n points = []\n dx = abs(x1 - x0)\n dy = abs(y1 - y0)\n x, y = x0, y0\n sx = -1 if x0 > x1 else 1\n sy = -1 if y0 > y1 else 1\n if dx > dy:\n err = dx / 2.0\n while x != x1:\n points.append((x, y))\n err -= dy\n if err < 0:\n y += sy\n err += dx\n x += sx\n else:\n err = dy / 2.0\n while y != y1:\n points.append((x\n err -= dx\n if err < 0:\n x += sx\n err += dy\n y += sy\n points.append((x, y))\n return points\n[end of /src/another_file.py]'
PROMPT_FUNCTIONS
module-attribute
PROMPT_FUNCTIONS = {'style-2': prompt_style_2, 'style-3': prompt_style_3, 'full_file_gen': full_file_gen, 'style-2-edits-only': prompt_style_2_edits_only}
add_lines_list
add_lines_list(content)
Source code in swebench/inference/make_datasets/create_instance.py
116 117 118 119 120 |
|
add_lines
add_lines(content)
Source code in swebench/inference/make_datasets/create_instance.py
123 124 |
|
make_code_text
make_code_text(files_dict, add_line_numbers=True)
Source code in swebench/inference/make_datasets/create_instance.py
127 128 129 130 131 132 133 134 135 136 |
|
make_code_text_edits_only
make_code_text_edits_only(files_dict, patch, add_line_numbers=True)
Source code in swebench/inference/make_datasets/create_instance.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
|
prompt_style_2
prompt_style_2(instance)
Source code in swebench/inference/make_datasets/create_instance.py
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|
prompt_style_2_edits_only
prompt_style_2_edits_only(instance)
Source code in swebench/inference/make_datasets/create_instance.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
|
prompt_style_3
prompt_style_3(instance)
Source code in swebench/inference/make_datasets/create_instance.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
full_file_gen
full_file_gen(instance)
Source code in swebench/inference/make_datasets/create_instance.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
|
ingest_files
ingest_files(filenames)
Source code in swebench/inference/make_datasets/create_instance.py
287 288 289 290 291 292 293 |
|
add_retrieval_results
add_retrieval_results(input_instances, retrieval_file, k, file_source)
Adds retrieval results to input_instances in-place
Source code in swebench/inference/make_datasets/create_instance.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
|
get_oracle_filenames
get_oracle_filenames(instance)
Returns the filenames that are changed in the patch
Source code in swebench/inference/make_datasets/create_instance.py
326 327 328 329 330 331 332 333 334 335 336 337 |
|
add_text_inputs
add_text_inputs(instances, retrieval_file, k, prompt_style, file_source, max_context_len=None, tokenizer_name=None, verbose=False, progress_file=None) -> None
Process instances and save results to progress file.
Args: - instances: dictionary with unprocessed input instances - retrieval_file: if using retrieval method for file_contents, specify retrieval_file - k: if using retrieval, specifies the maximum number of files to include - prompt_style: specify the function to generate instructions and prompt - file_source: where to collect file_contents (e.g. oracle or bm25) - verbose: set ContextManager verbose to True - progress_file: required, path to save processed instances
Source code in swebench/inference/make_datasets/create_instance.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 |
|
create_text_dataset
Create a dataset for text-to-text training from the raw task instance outputs.
logger
module-attribute
logger = getLogger(__name__)
parser
module-attribute
parser = ArgumentParser(description=__doc__)
load_jsonl_file
load_jsonl_file(filename)
Source code in swebench/inference/make_datasets/create_text_dataset.py
25 26 27 28 29 30 31 32 33 34 35 |
|
instances_generator
instances_generator(files)
Source code in swebench/inference/make_datasets/create_text_dataset.py
38 39 40 41 42 |
|
get_training_and_eval_instances
get_training_and_eval_instances(raw_files, test_dataset)
Source code in swebench/inference/make_datasets/create_text_dataset.py
45 46 47 48 49 50 51 52 53 54 55 |
|
extract_fields
extract_fields(instance)
Source code in swebench/inference/make_datasets/create_text_dataset.py
58 59 60 61 62 63 64 65 66 67 68 |
|
validate_arguments
validate_arguments(push_to_hub_user, output_dir, max_context_len, tokenizer_name, file_source, k)
Validate command line arguments and environment setup.
Source code in swebench/inference/make_datasets/create_text_dataset.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
construct_output_filename
construct_output_filename(dataset_name, prompt_style, file_source, k, max_context_len, tokenizer_name)
Construct the output filename based on parameters.
Source code in swebench/inference/make_datasets/create_text_dataset.py
99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
main
main(dataset_name_or_path, splits, validation_ratio, output_dir, retrieval_file, prompt_style, file_source, k, max_context_len, tokenizer_name, push_to_hub_user)
Source code in swebench/inference/make_datasets/create_text_dataset.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
eval_retrieval
This script can be used to evaluate the BM25 retrieval results for a dataset created with create_text_dataset.py with the --retrieval_file option and --file_source bm25.
logger
module-attribute
logger = getLogger(__name__)
parser
module-attribute
parser = ArgumentParser(description=__doc__)
args
module-attribute
args = parse_args()
main
main(dataset_name_or_path, split)
Source code in swebench/inference/make_datasets/eval_retrieval.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
tokenize_dataset
Provided a source (raw) directory and the final (eval) directory, create a training split by removing all instances that are in the final directory from the source directory.
logger
module-attribute
logger = getLogger(__name__)
TOKENIZER_FUNCS
module-attribute
TOKENIZER_FUNCS = {'cl100k': (get_encoding('cl100k_base'), cl100k), 'llama': (from_pretrained('togethercomputer/LLaMA-2-7B-32K'), llama)}
parser
module-attribute
parser = ArgumentParser(description=__doc__)
cl100k
cl100k(text, tokenizer)
Source code in swebench/inference/make_datasets/tokenize_dataset.py
21 22 |
|
llama
llama(text, tokenizer)
Source code in swebench/inference/make_datasets/tokenize_dataset.py
25 26 27 28 |
|
extract_fields
extract_fields(instance, tokenizer_name, tokenizer, tokenizer_func, eos_token)
Source code in swebench/inference/make_datasets/tokenize_dataset.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
extract_test_fields
extract_test_fields(instance, tokenizer_name, tokenizer, tokenizer_func, eos_token)
Source code in swebench/inference/make_datasets/tokenize_dataset.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
add_columns_from_dict
add_columns_from_dict(dataset, dict_columns)
dict_columns is a list of dicts with keys that are columns in dataset
Source code in swebench/inference/make_datasets/tokenize_dataset.py
99 100 101 102 103 104 105 106 |
|
main
main(dataset_name_or_path, output_dir, tokenizer_name, num_proc, push_to_hub_user)
Source code in swebench/inference/make_datasets/tokenize_dataset.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
utils
DIFF_PATTERN
module-attribute
DIFF_PATTERN = compile('^diff(?:.*)')
PATCH_PATTERN
module-attribute
PATCH_PATTERN = compile('(?:diff[\\w\\_\\.\\ \\/\\-]+\\n)?\\-\\-\\-\\s+a\\/(?:.*?)\\n\\+\\+\\+\\s+b\\/(?:.*?)(?=diff\\ |\\-\\-\\-\\ a\\/|\\Z)', DOTALL)
PATCH_FILE_PATTERN
module-attribute
PATCH_FILE_PATTERN = compile('\\-\\-\\-\\s+a\\/(?:.+)\\n\\+\\+\\+\\s+b\\/(?:.+)')
PATCH_HUNK_PATTERN
module-attribute
PATCH_HUNK_PATTERN = compile('\\@\\@\\s+\\-(\\d+),(\\d+)\\s+\\+(\\d+),(\\d+)\\s+\\@\\@(.+?)(?=diff\\ |\\-\\-\\-\\ a\\/|\\@\\@\\ \\-|\\Z)', DOTALL)
ContextManager
ContextManager(repo_path, base_commit, verbose=False)
Source code in swebench/inference/make_datasets/utils.py
149 150 151 152 153 |
|
repo_path
instance-attribute
repo_path = as_posix()
old_dir
instance-attribute
old_dir = getcwd()
base_commit
instance-attribute
base_commit = base_commit
verbose
instance-attribute
verbose = verbose
__enter__
__enter__()
Source code in swebench/inference/make_datasets/utils.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
get_environment
get_environment()
Source code in swebench/inference/make_datasets/utils.py
170 171 |
|
get_readme_files
get_readme_files()
Source code in swebench/inference/make_datasets/utils.py
173 174 175 176 177 |
|
__exit__
__exit__(exc_type, exc_val, exc_tb)
Source code in swebench/inference/make_datasets/utils.py
179 180 |
|
AutoContextManager
AutoContextManager(instance, root_dir=None, verbose=False, token=None)
Bases: ContextManager
Automatically clones the repo if it doesn't exist
Source code in swebench/inference/make_datasets/utils.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
|
tempdir
instance-attribute
tempdir = None
root_dir
instance-attribute
root_dir = root_dir
instance
instance-attribute
instance = instance
__exit__
__exit__(exc_type, exc_val, exc_tb)
Source code in swebench/inference/make_datasets/utils.py
207 208 209 210 |
|
get_first_idx
get_first_idx(charlist)
Source code in swebench/inference/make_datasets/utils.py
24 25 26 27 |
|
get_last_idx
get_last_idx(charlist)
Source code in swebench/inference/make_datasets/utils.py
30 31 32 33 |
|
strip_content
strip_content(hunk)
Source code in swebench/inference/make_datasets/utils.py
36 37 38 39 40 41 42 |
|
get_hunk_stats
get_hunk_stats(pre_start, pre_len, post_start, post_len, hunk, total_delta)
Source code in swebench/inference/make_datasets/utils.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
repair_patch
repair_patch(model_patch)
Source code in swebench/inference/make_datasets/utils.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
extract_minimal_patch
extract_minimal_patch(model_patch)
Source code in swebench/inference/make_datasets/utils.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
extract_diff
extract_diff(response)
Extracts the diff from a response formatted in different ways
Source code in swebench/inference/make_datasets/utils.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
is_test
is_test(name, test_phrases=None)
Source code in swebench/inference/make_datasets/utils.py
141 142 143 144 145 |
|
get_imported_modules
get_imported_modules(filename)
Source code in swebench/inference/make_datasets/utils.py
213 214 215 216 217 218 219 220 |
|
resolve_module_to_file
resolve_module_to_file(module, level, root_dir)
Source code in swebench/inference/make_datasets/utils.py
223 224 225 226 227 228 229 230 231 232 233 234 |
|
ingest_file_directory_contents
ingest_file_directory_contents(target_file, root_dir)
Source code in swebench/inference/make_datasets/utils.py
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
detect_encoding
detect_encoding(filename)
Detect the encoding of a file
Source code in swebench/inference/make_datasets/utils.py
259 260 261 262 263 264 265 |
|
list_files
list_files(root_dir, include_tests=False)
Source code in swebench/inference/make_datasets/utils.py
268 269 270 271 272 273 274 |
|
ingest_directory_contents
ingest_directory_contents(root_dir, include_tests=False)
Source code in swebench/inference/make_datasets/utils.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
|
string_to_bool
string_to_bool(v)
Source code in swebench/inference/make_datasets/utils.py
294 295 296 297 298 299 300 301 302 303 304 |
|
run_api
This python script is designed to run inference on a dataset using either the OpenAI or Anthropic API, depending on the model specified. It sorts instances by length and continually writes the outputs to a specified file, so that the script can be stopped and restarted without losing progress.
logger
module-attribute
logger = getLogger(__name__)
MODEL_LIMITS
module-attribute
MODEL_LIMITS = {'claude-instant-1': 100000, 'claude-2': 100000, 'claude-3-opus-20240229': 200000, 'claude-3-sonnet-20240229': 200000, 'claude-3-haiku-20240307': 200000, 'gpt-3.5-turbo-16k-0613': 16385, 'gpt-3.5-turbo-0613': 4097, 'gpt-3.5-turbo-1106': 16385, 'gpt-4-32k-0613': 32768, 'gpt-4-0613': 8192, 'gpt-4-1106-preview': 128000, 'gpt-4-0125-preview': 128000}
MODEL_COST_PER_INPUT
module-attribute
MODEL_COST_PER_INPUT = {'claude-instant-1': 1.63e-06, 'claude-2': 1.102e-05, 'claude-3-opus-20240229': 1.5e-05, 'claude-3-sonnet-20240229': 3e-06, 'claude-3-haiku-20240307': 2.5e-07, 'gpt-3.5-turbo-16k-0613': 1.5e-06, 'gpt-3.5-turbo-0613': 1.5e-06, 'gpt-3.5-turbo-1106': 1e-06, 'gpt-35-turbo-0613': 1.5e-06, 'gpt-35-turbo': 1.5e-06, 'gpt-4-0613': 3e-05, 'gpt-4-32k-0613': 6e-05, 'gpt-4-32k': 6e-05, 'gpt-4-1106-preview': 1e-05, 'gpt-4-0125-preview': 1e-05}
MODEL_COST_PER_OUTPUT
module-attribute
MODEL_COST_PER_OUTPUT = {'claude-instant-1': 5.51e-06, 'claude-2': 3.268e-05, 'claude-3-opus-20240229': 7.5e-05, 'claude-3-sonnet-20240229': 1.5e-05, 'claude-3-haiku-20240307': 1.25e-06, 'gpt-3.5-turbo-16k-0613': 2e-06, 'gpt-3.5-turbo-16k': 2e-06, 'gpt-3.5-turbo-1106': 2e-06, 'gpt-35-turbo-0613': 2e-06, 'gpt-35-turbo': 2e-06, 'gpt-4-0613': 6e-05, 'gpt-4-32k-0613': 0.00012, 'gpt-4-32k': 0.00012, 'gpt-4-1106-preview': 3e-05, 'gpt-4-0125-preview': 3e-05}
ENGINES
module-attribute
ENGINES = {'gpt-3.5-turbo-16k-0613': 'gpt-35-turbo-16k', 'gpt-4-0613': 'gpt-4', 'gpt-4-32k-0613': 'gpt-4-32k'}
parser
module-attribute
parser = ArgumentParser(description=__doc__)
args
module-attribute
args = parse_args()
calc_cost
calc_cost(model_name, input_tokens, output_tokens)
Calculates the cost of a response from the openai API.
Args: response (openai.ChatCompletion): The response from the API.
Returns: float: The cost of the response.
Source code in swebench/inference/run_api.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
call_chat
call_chat(model_name_or_path, inputs, use_azure, temperature, top_p, **model_args)
Calls the openai API to generate completions for the given inputs.
Args: model_name_or_path (str): The name or path of the model to use. inputs (str): The inputs to generate completions for. use_azure (bool): Whether to use the azure API. temperature (float): The temperature to use. top_p (float): The top_p to use. **model_args (dict): A dictionary of model arguments.
Source code in swebench/inference/run_api.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
gpt_tokenize
gpt_tokenize(string: str, encoding) -> int
Returns the number of tokens in a text string.
Source code in swebench/inference/run_api.py
162 163 164 165 |
|
claude_tokenize
claude_tokenize(string: str, api) -> int
Returns the number of tokens in a text string.
Source code in swebench/inference/run_api.py
168 169 170 171 |
|
openai_inference
openai_inference(test_dataset, model_name_or_path, output_file, model_args, existing_ids, max_cost)
Runs inference on a dataset using the openai API.
Args: test_dataset (datasets.Dataset): The dataset to run inference on. model_name_or_path (str): The name or path of the model to use. output_file (str): The path to the output file. model_args (dict): A dictionary of model arguments. existing_ids (set): A set of ids that have already been processed. max_cost (float): The maximum cost to spend on inference.
Source code in swebench/inference/run_api.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
|
call_anthropic
call_anthropic(inputs, anthropic, model_name_or_path, temperature, top_p, **model_args)
Calls the anthropic API to generate completions for the given inputs.
Args: inputs (str): The inputs to generate completions for. anthropic (Anthropic): The anthropic API object. model_name_or_path (str): The name or path of the model to use. temperature (float): The temperature to use. top_p (float): The top_p to use. model_args (dict): A dictionary of model arguments.
Source code in swebench/inference/run_api.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
|
call_anthropic_v2
call_anthropic_v2(inputs, anthropic, model_name_or_path, temperature, top_p, **model_args)
Calls the anthropic API to generate completions for the given inputs.
Args: inputs list(str): The inputs to generate completions for. anthropic (Anthropic): The anthropic API object. model_name_or_path (str): The name or path of the model to use. temperature (float): The temperature to use. top_p (float): The top_p to use. model_args (dict): A dictionary of model arguments.
Source code in swebench/inference/run_api.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
anthropic_inference
anthropic_inference(test_dataset, model_name_or_path, output_file, model_args, existing_ids, max_cost)
Runs inference on a dataset using the anthropic API.
Args: test_dataset (datasets.Dataset): The dataset to run inference on. model_name_or_path (str): The name or path of the model to use. output_file (str): The path to the output file. model_args (dict): A dictionary of model arguments. existing_ids (set): A set of ids that have already been processed. max_cost (float): The maximum cost to spend on inference.
Source code in swebench/inference/run_api.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
|
parse_model_args
parse_model_args(model_args)
Parses a string of model arguments and returns a dictionary of keyword arguments.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_args
|
str
|
A string of comma-separated key-value pairs representing model arguments. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
A dictionary of keyword arguments parsed from the input string. |
Source code in swebench/inference/run_api.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
|
main
main(dataset_name_or_path, split, model_name_or_path, shard_id, num_shards, output_dir, model_args, max_cost)
Source code in swebench/inference/run_api.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
|
run_live
This module contains functions for running a live inference session on a GitHub issue. It clones the repository associated with the issue, builds a BM25 retrieval index, and generates a prompt for the user to interact with the model. The output is saved to a specified directory.
logger
module-attribute
logger = getLogger(__name__)
parser
module-attribute
parser = ArgumentParser(description=__doc__)
args
module-attribute
args = parse_args()
get_problem_statement
get_problem_statement(owner, repo, issue_num, ghapi, include_comments=False)
Source code in swebench/inference/run_live.py
47 48 49 50 51 52 53 54 55 56 |
|
get_readme_files
get_readme_files(repo_path)
Source code in swebench/inference/run_live.py
59 60 61 62 63 64 65 66 |
|
make_instance
make_instance(owner, repo, query, commit, root_dir, token, document_encoding_func, python, instance_id, tokenizer, tokenizer_func, prompt_style, max_context_len, include_readmes)
Creates an instance for a given query and repository.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
owner
|
str
|
The owner of the repository. |
required |
repo
|
str
|
The name of the repository. |
required |
query
|
str
|
The query to search for. |
required |
commit
|
str
|
The commit hash to use. |
required |
root_dir
|
str
|
The root directory to clone the repository to. |
required |
token
|
str
|
The GitHub token to use for authentication. |
required |
document_encoding_func
|
function
|
The function to use for encoding documents. |
required |
python
|
str
|
The path to the Python executable. |
required |
instance_id
|
int
|
The ID of the instance. |
required |
tokenizer
|
str
|
The name of the tokenizer to use. |
required |
tokenizer_func
|
function
|
The function to use for tokenization. |
required |
prompt_style
|
str
|
The style of prompt to use. |
required |
max_context_len
|
int
|
The maximum length of the context. |
required |
include_readmes
|
bool
|
Whether to include README files in the instance. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
The instance. |
Source code in swebench/inference/run_live.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
parse_issue_url
parse_issue_url(issue_url)
Source code in swebench/inference/run_live.py
161 162 163 164 165 166 167 168 169 170 |
|
main
main(model_name, prompt_style, issue_url, base_commit, max_context_length, document_encoding_func, output_dir, root_dir, include_readmes)
Source code in swebench/inference/run_live.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
run_llama
logger
module-attribute
logger = getLogger(__name__)
DEVICE_MAPS
module-attribute
DEVICE_MAPS = load(open(parent / 'codellama_device_maps.json'))
parser
module-attribute
parser = ArgumentParser()
args
module-attribute
args = parse_args()
get_output_file
get_output_file(output_dir, model_name_or_path, peft_path, dataset_path, split, temperature, top_p, min_len, max_len, shard_id, num_shards)
Constructs the output file path based on the provided parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
output_dir
|
str
|
The directory where the output file will be saved. |
required |
model_name_or_path
|
str
|
The name or path of the model. |
required |
peft_path
|
str
|
The path to the PEFT file. |
required |
dataset_path
|
str
|
The path to the dataset. |
required |
split
|
str
|
The dataset split. |
required |
temperature
|
float
|
The temperature value. |
required |
top_p
|
float
|
The top-p value. |
required |
min_len
|
int
|
The minimum length of the output. |
required |
max_len
|
int
|
The maximum length of the output. |
required |
shard_id
|
int
|
The shard ID. |
required |
num_shards
|
int
|
The total number of shards. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
The constructed output file path. |
Source code in swebench/inference/run_llama.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
load_model
load_model(model_name_or_path, peft_path)
Loads a base model and optionally PEFT adapters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_name_or_path
|
str
|
The name or path of the base model. |
required |
peft_path
|
str or None
|
The path to the PEFT adapters. If None, no PEFT adapters will be loaded. |
required |
Returns:
Name | Type | Description |
---|---|---|
model |
The loaded model. |
Raises:
Type | Description |
---|---|
ValueError
|
If there is no device map for the specified model_name_or_path. |
Source code in swebench/inference/run_llama.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
|
load_tokenizer
load_tokenizer(model_name_or_path)
Source code in swebench/inference/run_llama.py
157 158 159 160 |
|
load_data
load_data(dataset_path, split, tokenizer, min_len, max_len, model_name_or_path, peft_path, existing_ids, shard_id, num_shards)
Load and preprocess the dataset for model inference.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset_path
|
str
|
The path to the dataset. |
required |
split
|
str
|
The split of the dataset to load. |
required |
tokenizer
|
The tokenizer used to tokenize the text. |
required | |
min_len
|
int
|
The minimum length of input sequences to include in the dataset. |
required |
max_len
|
int
|
The maximum length of input sequences to include in the dataset. |
required |
model_name_or_path
|
str
|
The name or path of the model. |
required |
peft_path
|
str
|
The path to the PEFT file. |
required |
existing_ids
|
The list of existing instance IDs to filter out from the dataset. |
required | |
shard_id
|
int
|
The ID of the shard to load. |
required |
num_shards
|
int
|
The total number of shards. |
required |
Returns:
Name | Type | Description |
---|---|---|
dataset |
The preprocessed dataset for model inference. |
Source code in swebench/inference/run_llama.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
generate
generate(model, dataset, tokenizer, temperature, top_p, fileobj, model_name_or_path, peft_path)
Source code in swebench/inference/run_llama.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
|
get_all_existing_ids
get_all_existing_ids(output_file)
Source code in swebench/inference/run_llama.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
|
main
main(model_name_or_path, peft_path, dataset_path, split, temperature, top_p, output_dir, min_len, max_len, shard_id, num_shards)
Source code in swebench/inference/run_llama.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
|