Run this model with HF Jobs
Run IQuestLab/IQuest-Coder-V1-7B-Instruct on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/IQuestLab/IQuest-Coder-V1-7B-Instruct. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/IQuestLab/IQuest-Coder-V1-7B-Instruct on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/IQuestLab/IQuest-Coder-V1-7B-Instruct. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/IQuestLab/IQuest-Coder-V1-7B-Instruct. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use IQuestLab/IQuest-Coder-V1-7B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use IQuestLab/IQuest-Coder-V1-7B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="IQuestLab/IQuest-Coder-V1-7B-Instruct", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("IQuestLab/IQuest-Coder-V1-7B-Instruct", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use IQuestLab/IQuest-Coder-V1-7B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "IQuestLab/IQuest-Coder-V1-7B-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "IQuestLab/IQuest-Coder-V1-7B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/IQuestLab/IQuest-Coder-V1-7B-Instruct
- SGLang
How to use IQuestLab/IQuest-Coder-V1-7B-Instruct with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "IQuestLab/IQuest-Coder-V1-7B-Instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "IQuestLab/IQuest-Coder-V1-7B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "IQuestLab/IQuest-Coder-V1-7B-Instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "IQuestLab/IQuest-Coder-V1-7B-Instruct", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use IQuestLab/IQuest-Coder-V1-7B-Instruct with Docker Model Runner:
docker model run hf.co/IQuestLab/IQuest-Coder-V1-7B-Instruct
Upload folder using huggingface_hub
Browse filesFiles changed (11)
- config.jsonAdded+33
- conversion_to_hf.logAdded+109
- generation_config.jsonAdded+6
- model-00001-of-00004.safetensorsAdded+3
- model-00002-of-00004.safetensorsAdded+3
- model-00003-of-00004.safetensorsAdded+3
- model-00004-of-00004.safetensorsAdded+3
- model.safetensors.index.jsonAdded+137
- tokenization_neo.pyAdded+246
- tokenizer.modelAdded+3
- tokenizer_config.jsonAdded+240
123456789101112131415161718192021222324252627282930313233{ "architectures": [ "LlamaForCausalLM" ], "attention_bias": false, "attention_dropout": 0.0, "bos_token_id": 1, "eos_token_id": [ 2, 75864, 75869 ], "head_dim": 128, "hidden_act": "silu", "hidden_size": 5120, "initializer_range": 0.02, "intermediate_size": 27648, "max_position_embeddings": 131072, "mlp_bias": false, "model_type": "llama", "num_attention_heads": 40, "num_hidden_layers": 14, "num_key_value_heads": 8, "pretraining_tp": 1, "rms_norm_eps": 1e-05, "rope_scaling": null, "rope_theta": 500000, "tie_word_embeddings": false, "torch_dtype": "bfloat16", "transformers_version": "4.40.0", "use_cache": true, "vocab_size": 76800}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109Loaded loader_megatron_core as the loader.Loaded saver_llama2_hf_bf as the saver.Starting saver...Starting loader...fused_indices_to_multihot has reached end of life. Please migrate to a non-experimental function./usr/local/lib/python3.12/dist-packages/modelopt/torch/utils/import_utils.py:31: UserWarning: Failed to import apex plugin due to: AttributeError("module 'transformers.modeling_utils' has no attribute 'Conv1D'"). You may ignore this warning if you do not need this plugin. warnings.warn(/usr/local/lib/python3.12/dist-packages/modelopt/torch/utils/import_utils.py:31: UserWarning: Failed to import huggingface plugin due to: AttributeError("module 'transformers.modeling_utils' has no attribute 'Conv1D'"). You may ignore this warning if you do not need this plugin. warnings.warn(/usr/local/lib/python3.12/dist-packages/modelopt/torch/utils/import_utils.py:31: UserWarning: Failed to import megatron plugin due to: AttributeError("module 'transformers.modeling_utils' has no attribute 'Conv1D'"). You may ignore this warning if you do not need this plugin. warnings.warn(Setting num_layers to 14 from checkpointSetting hidden_size to 5120 from checkpointSetting ffn_hidden_size to 27648 from checkpointSetting seq_length to 131072 from checkpointSetting num_attention_heads to 40 from checkpointSetting num_query_groups to 8 from checkpointSetting group_query_attention to True from checkpointSetting kv_channels to 128 from checkpointSetting max_position_embeddings to 131072 from checkpointSetting position_embedding_type to rope from checkpointSetting add_position_embedding to True from checkpointSetting use_rotary_position_embeddings to True from checkpointSetting rotary_base to 500000 from checkpointSetting rotary_percent to 1.0 from checkpointSetting rotary_interleaved to False from checkpointSetting add_bias_linear to False from checkpointSetting add_qkv_bias to False from checkpointSetting squared_relu to False from checkpointSetting swiglu to True from checkpointSetting untie_embeddings_and_output_weights to True from checkpointSetting apply_layernorm_1p to False from checkpointSetting normalization to RMSNorm from checkpointSetting apply_query_key_layer_scaling to False from checkpointSetting attention_dropout to 0.0 from checkpointSetting hidden_dropout to 0.0 from checkpointCheckpoint did not provide arguments hybrid_override_patternCheckpoint did not provide arguments specSetting hybrid_attention_ratio to 0.0 from checkpointSetting hybrid_mlp_ratio to 0.0 from checkpointCheckpoint did not provide arguments num_expertsSetting moe_layer_freq to 1 from checkpointSetting moe_router_topk to 2 from checkpointSetting moe_router_pre_softmax to False from checkpointSetting moe_grouped_gemm to False from checkpointCheckpoint did not provide arguments moe_shared_expert_intermediate_sizeSetting mamba_state_dim to 128 from checkpointSetting mamba_head_dim to 64 from checkpointSetting mamba_num_groups to 8 from checkpointCheckpoint did not provide arguments mamba_num_headsSetting is_hybrid_model to False from checkpointCheckpoint did not provide arguments heterogeneous_layers_config_pathCheckpoint did not provide arguments heterogeneous_layers_config_encoded_jsonSetting tokenizer_type to SFTTokenizer from checkpointSetting tokenizer_model to /cpfs01/users/wzhang/iquest-coder-v1.1/RepoData-Ucoder-32B-128k-from2.5.2/97.09B_instruct_iquest-coder from checkpointCheckpoint did not provide arguments tiktoken_patternSetting padded_vocab_size to 76800 from checkpointINFO:megatron.core.num_microbatches_calculator:setting number of microbatches to constant 1WARNING: one_logger package is required to enable e2e metrics tracking. please go to https://confluence.nvidia.com/display/MLWFO/Package+Repositories for details to install itbuilding GPT model ...(TP, PP) mismatch after resume ((1, 1) vs (8, 1) from checkpoint): RNG state will be ignoredsharded_state_dict metadata loaded from the checkpoint: {'distrib_optim_sharding_type': 'dp_reshardable', 'singleton_local_shards': False, 'chained_optim_avoid_prefix': True}Job sharding has changed: Rerun state will be ignored loading distributed checkpoint from /tmp/megatron_convert_iter1717_node0_pid360_aefde564 at iteration 1717/volume/pt-train/users/wzhang/wjj-workspace/code-sft/src/training/Megatron-LM/megatron/core/dist_checkpointing/strategies/torch.py:956: FutureWarning: `load_state_dict` is deprecated and will be removed in future versions. Please use `load` instead. checkpoint.load_state_dict(/usr/local/lib/python3.12/dist-packages/torch/distributed/checkpoint/planner_helpers.py:406: FutureWarning: Please use DTensor instead and we are deprecating ShardedTensor. device = getattr(value, "device", None)/usr/local/lib/python3.12/dist-packages/torch/distributed/checkpoint/default_planner.py:454: FutureWarning: Please use DTensor instead and we are deprecating ShardedTensor. and md.size != obj.size() checkpoint version 3.0 successfully loaded checkpoint from /tmp/megatron_convert_iter1717_node0_pid360_aefde564 [ t 1/1, p 1/1 ] at iteration 1717sending embeddingssending transformer layer 0sending transformer layer 1sending transformer layer 2sending transformer layer 3sending transformer layer 4sending transformer layer 5sending transformer layer 6sending transformer layer 7sending transformer layer 8sending transformer layer 9sending transformer layer 10sending transformer layer 11sending transformer layer 12sending transformer layer 13sending final normsending output layerWaiting for saver to complete...fused_indices_to_multihot has reached end of life. Please migrate to a non-experimental function.received embeddingsreceived transformer layer 0received transformer layer 1received transformer layer 2received transformer layer 3received transformer layer 4received transformer layer 5received transformer layer 6received transformer layer 7received transformer layer 8received transformer layer 9received transformer layer 10received transformer layer 11received transformer layer 12received transformer layer 13received final normreceived output layerSaving model to disk ...123456{ "_from_model_config": true, "bos_token_id": 1, "eos_token_id": [2, 75864, 75869], "transformers_version": "4.55.4"}123version https://git-lfs.github.com/spec/v1oid sha256:36490fb7da78748a764f9da895bbfe7f09cca10af4cd044f8c297b0280a19128size 4813050528123version https://git-lfs.github.com/spec/v1oid sha256:002038e8e517f50e9897bd6ea58eb93ff5e602eeb3141e19904b67360d099c63size 4875986024123version https://git-lfs.github.com/spec/v1oid sha256:c5494edd52a7f492ede831d4b186fdc6200f2ac9e9926b1fca79107bf06a3d4bsize 4750166792123version https://git-lfs.github.com/spec/v1oid sha256:75f304bda59fdfcc48db42c8b80dc9a23d7a16165cecafd088c698cda023a2b2size 786432128123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137{ "metadata": { "total_parameters": 7612810240, "total_size": 15225620480 }, "weight_map": { "lm_head.weight": "model-00004-of-00004.safetensors", "model.embed_tokens.weight": "model-00001-of-00004.safetensors", "model.layers.0.input_layernorm.weight": "model-00001-of-00004.safetensors", "model.layers.0.mlp.down_proj.weight": "model-00001-of-00004.safetensors", "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00004.safetensors", "model.layers.0.mlp.up_proj.weight": "model-00001-of-00004.safetensors", "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00004.safetensors", "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00004.safetensors", "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00004.safetensors", "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00004.safetensors", "model.layers.1.input_layernorm.weight": "model-00001-of-00004.safetensors", "model.layers.1.mlp.down_proj.weight": "model-00001-of-00004.safetensors", "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00004.safetensors", "model.layers.1.mlp.up_proj.weight": "model-00001-of-00004.safetensors", "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00004.safetensors", "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00004.safetensors", "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00004.safetensors", "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00004.safetensors", "model.layers.10.input_layernorm.weight": "model-00003-of-00004.safetensors", "model.layers.10.mlp.down_proj.weight": "model-00003-of-00004.safetensors", "model.layers.10.mlp.gate_proj.weight": "model-00003-of-00004.safetensors", "model.layers.10.mlp.up_proj.weight": "model-00003-of-00004.safetensors", "model.layers.10.post_attention_layernorm.weight": "model-00003-of-00004.safetensors", "model.layers.10.self_attn.k_proj.weight": "model-00003-of-00004.safetensors", "model.layers.10.self_attn.o_proj.weight": "model-00003-of-00004.safetensors", "model.layers.10.self_attn.q_proj.weight": "model-00003-of-00004.safetensors", "model.layers.10.self_attn.v_proj.weight": "model-00003-of-00004.safetensors", "model.layers.11.input_layernorm.weight": "model-00003-of-00004.safetensors", "model.layers.11.mlp.down_proj.weight": "model-00003-of-00004.safetensors", "model.layers.11.mlp.gate_proj.weight": "model-00003-of-00004.safetensors", "model.layers.11.mlp.up_proj.weight": "model-00003-of-00004.safetensors", "model.layers.11.post_attention_layernorm.weight": "model-00003-of-00004.safetensors", "model.layers.11.self_attn.k_proj.weight": "model-00003-of-00004.safetensors", "model.layers.11.self_attn.o_proj.weight": "model-00003-of-00004.safetensors", "model.layers.11.self_attn.q_proj.weight": "model-00003-of-00004.safetensors", "model.layers.11.self_attn.v_proj.weight": "model-00003-of-00004.safetensors", "model.layers.12.input_layernorm.weight": "model-00003-of-00004.safetensors", "model.layers.12.mlp.down_proj.weight": "model-00003-of-00004.safetensors", "model.layers.12.mlp.gate_proj.weight": "model-00003-of-00004.safetensors", "model.layers.12.mlp.up_proj.weight": "model-00003-of-00004.safetensors", "model.layers.12.post_attention_layernorm.weight": "model-00003-of-00004.safetensors", "model.layers.12.self_attn.k_proj.weight": "model-00003-of-00004.safetensors", "model.layers.12.self_attn.o_proj.weight": "model-00003-of-00004.safetensors", "model.layers.12.self_attn.q_proj.weight": "model-00003-of-00004.safetensors", "model.layers.12.self_attn.v_proj.weight": "model-00003-of-00004.safetensors", "model.layers.13.input_layernorm.weight": "model-00003-of-00004.safetensors", "model.layers.13.mlp.down_proj.weight": "model-00003-of-00004.safetensors", "model.layers.13.mlp.gate_proj.weight": "model-00003-of-00004.safetensors", "model.layers.13.mlp.up_proj.weight": "model-00003-of-00004.safetensors", "model.layers.13.post_attention_layernorm.weight": "model-00003-of-00004.safetensors", "model.layers.13.self_attn.k_proj.weight": "model-00003-of-00004.safetensors", "model.layers.13.self_attn.o_proj.weight": "model-00003-of-00004.safetensors", "model.layers.13.self_attn.q_proj.weight": "model-00003-of-00004.safetensors", "model.layers.13.self_attn.v_proj.weight": "model-00003-of-00004.safetensors", "model.layers.2.input_layernorm.weight": "model-00001-of-00004.safetensors", "model.layers.2.mlp.down_proj.weight": "model-00001-of-00004.safetensors", "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00004.safetensors", "model.layers.2.mlp.up_proj.weight": "model-00001-of-00004.safetensors", "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00004.safetensors", "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00004.safetensors", "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00004.safetensors", "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00004.safetensors", "model.layers.3.input_layernorm.weight": "model-00001-of-00004.safetensors", "model.layers.3.mlp.down_proj.weight": "model-00001-of-00004.safetensors", "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00004.safetensors", "model.layers.3.mlp.up_proj.weight": "model-00001-of-00004.safetensors", "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00004.safetensors", "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00004.safetensors", "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00004.safetensors", "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00004.safetensors", "model.layers.4.input_layernorm.weight": "model-00002-of-00004.safetensors", "model.layers.4.mlp.down_proj.weight": "model-00002-of-00004.safetensors", "model.layers.4.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", "model.layers.4.mlp.up_proj.weight": "model-00002-of-00004.safetensors", "model.layers.4.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00004.safetensors", "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00004.safetensors", "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00004.safetensors", "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00004.safetensors", "model.layers.5.input_layernorm.weight": "model-00002-of-00004.safetensors", "model.layers.5.mlp.down_proj.weight": "model-00002-of-00004.safetensors", "model.layers.5.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", "model.layers.5.mlp.up_proj.weight": "model-00002-of-00004.safetensors", "model.layers.5.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", "model.layers.5.self_attn.k_proj.weight": "model-00002-of-00004.safetensors", "model.layers.5.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", "model.layers.5.self_attn.q_proj.weight": "model-00002-of-00004.safetensors", "model.layers.5.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", "model.layers.6.input_layernorm.weight": "model-00002-of-00004.safetensors", "model.layers.6.mlp.down_proj.weight": "model-00002-of-00004.safetensors", "model.layers.6.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", "model.layers.6.mlp.up_proj.weight": "model-00002-of-00004.safetensors", "model.layers.6.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", "model.layers.6.self_attn.k_proj.weight": "model-00002-of-00004.safetensors", "model.layers.6.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", "model.layers.6.self_attn.q_proj.weight": "model-00002-of-00004.safetensors", "model.layers.6.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", "model.layers.7.input_layernorm.weight": "model-00002-of-00004.safetensors", "model.layers.7.mlp.down_proj.weight": "model-00002-of-00004.safetensors", "model.layers.7.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", "model.layers.7.mlp.up_proj.weight": "model-00002-of-00004.safetensors", "model.layers.7.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", "model.layers.7.self_attn.k_proj.weight": "model-00002-of-00004.safetensors", "model.layers.7.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", "model.layers.7.self_attn.q_proj.weight": "model-00002-of-00004.safetensors", "model.layers.7.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", "model.layers.8.input_layernorm.weight": "model-00002-of-00004.safetensors", "model.layers.8.mlp.down_proj.weight": "model-00002-of-00004.safetensors", "model.layers.8.mlp.gate_proj.weight": "model-00002-of-00004.safetensors", "model.layers.8.mlp.up_proj.weight": "model-00002-of-00004.safetensors", "model.layers.8.post_attention_layernorm.weight": "model-00002-of-00004.safetensors", "model.layers.8.self_attn.k_proj.weight": "model-00002-of-00004.safetensors", "model.layers.8.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", "model.layers.8.self_attn.q_proj.weight": "model-00002-of-00004.safetensors", "model.layers.8.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", "model.layers.9.input_layernorm.weight": "model-00003-of-00004.safetensors", "model.layers.9.mlp.down_proj.weight": "model-00003-of-00004.safetensors", "model.layers.9.mlp.gate_proj.weight": "model-00003-of-00004.safetensors", "model.layers.9.mlp.up_proj.weight": "model-00003-of-00004.safetensors", "model.layers.9.post_attention_layernorm.weight": "model-00003-of-00004.safetensors", "model.layers.9.self_attn.k_proj.weight": "model-00002-of-00004.safetensors", "model.layers.9.self_attn.o_proj.weight": "model-00002-of-00004.safetensors", "model.layers.9.self_attn.q_proj.weight": "model-00002-of-00004.safetensors", "model.layers.9.self_attn.v_proj.weight": "model-00002-of-00004.safetensors", "model.norm.weight": "model-00003-of-00004.safetensors" }}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246# Copyright 2024 NEO Inc. All Rights Reserved.
# Copyright 2022 EleutherAI and the HuggingFace Inc. team. All rights reserved.## This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX# and OPT implementations in this library. It has been modified from its# original forms to accommodate minor architectural differences compared# to GPT-NeoX and OPT used by the Meta AI team that trained the model.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.
import osfrom shutil import copyfilefrom typing import Any, Dict, List, Optional, Tuple
import sentencepiece as spm
from transformers.tokenization_utils import AddedToken, PreTrainedTokenizerfrom transformers.utils import logging
logger = logging.get_logger(__name__)
VOCAB_FILES_NAMES = {"vocab_file": "tokenizer.model"}
PRETRAINED_VOCAB_FILES_MAP = { "vocab_file": {}, "tokenizer_file": {},}PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES = {}
class NEOTokenizer(PreTrainedTokenizer): """ Construct a NEO tokenizer. Based on byte-level Byte-Pair-Encoding. Args: vocab_file (`str`): Path to the vocabulary file. """
vocab_files_names = VOCAB_FILES_NAMES pretrained_vocab_files_map = PRETRAINED_VOCAB_FILES_MAP max_model_input_sizes = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES model_input_names = ["input_ids", "attention_mask"]
def __init__( self, vocab_file, unk_token="<unk>", bos_token="<s>", eos_token="</s>", pad_token=None, sp_model_kwargs: Optional[Dict[str, Any]] = None, add_bos_token=True, add_eos_token=False, clean_up_tokenization_spaces=False, **kwargs, ): self.sp_model_kwargs = {} if sp_model_kwargs is None else sp_model_kwargs bos_token = AddedToken(bos_token, lstrip=False, rstrip=False) if isinstance(bos_token, str) else bos_token eos_token = AddedToken(eos_token, lstrip=False, rstrip=False) if isinstance(eos_token, str) else eos_token unk_token = AddedToken(unk_token, lstrip=False, rstrip=False) if isinstance(unk_token, str) else unk_token pad_token = AddedToken(pad_token, lstrip=False, rstrip=False) if isinstance(pad_token, str) else pad_token self.vocab_file = vocab_file self.add_bos_token = add_bos_token self.add_eos_token = add_eos_token self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs) self.sp_model.Load(vocab_file) super().__init__( bos_token=bos_token, eos_token=eos_token, unk_token=unk_token, pad_token=pad_token, add_bos_token=add_bos_token, add_eos_token=add_eos_token, sp_model_kwargs=self.sp_model_kwargs, clean_up_tokenization_spaces=clean_up_tokenization_spaces, **kwargs, )
def __getstate__(self): state = self.__dict__.copy() state["sp_model"] = None return state
def __setstate__(self, d): self.__dict__ = d self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs) self.sp_model.Load(self.vocab_file)
@property def vocab_size(self): """Returns vocab size""" return self.sp_model.get_piece_size()
def get_vocab(self): """Returns vocab as a dict""" vocab = {self.convert_ids_to_tokens(i): i for i in range(self.vocab_size)} vocab.update(self.added_tokens_encoder) return vocab
def _tokenize(self, text): """Returns a tokenized string.""" return self.sp_model.encode(text, out_type=str)
def _convert_token_to_id(self, token): """Converts a token (str) in an id using the vocab.""" return self.sp_model.piece_to_id(token)
def _convert_id_to_token(self, index): """Converts an index (integer) in a token (str) using the vocab.""" token = self.sp_model.IdToPiece(index) return token
def convert_tokens_to_string(self, tokens): """Converts a sequence of tokens (string) in a single string.""" current_sub_tokens = [] out_string = "" prev_is_special = False for i, token in enumerate(tokens): # make sure that special tokens are not decoded using sentencepiece model if token in self.all_special_tokens: if not prev_is_special and i != 0: out_string += " " out_string += self.sp_model.decode(current_sub_tokens) + token prev_is_special = True current_sub_tokens = [] else: current_sub_tokens.append(token) prev_is_special = False out_string += self.sp_model.decode(current_sub_tokens) return out_string
def save_vocabulary(self, save_directory, filename_prefix: Optional[str] = None) -> Tuple[str]: """ Save the vocabulary and special tokens file to a directory. Args: save_directory (`str`): The directory in which to save the vocabulary. Returns: `Tuple(str)`: Paths to the files saved. """ if not os.path.isdir(save_directory): logger.error(f"Vocabulary path ({save_directory}) should be a directory") return out_vocab_file = os.path.join( save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"] )
if os.path.abspath(self.vocab_file) != os.path.abspath(out_vocab_file) and os.path.isfile(self.vocab_file): copyfile(self.vocab_file, out_vocab_file) elif not os.path.isfile(self.vocab_file): with open(out_vocab_file, "wb") as fi: content_spiece_model = self.sp_model.serialized_model_proto() fi.write(content_spiece_model)
return (out_vocab_file,)
def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None): bos_token_id = [self.bos_token_id] if self.add_bos_token else [] eos_token_id = [self.eos_token_id] if self.add_eos_token else []
output = bos_token_id + token_ids_0 + eos_token_id
if token_ids_1 is not None: output = output + bos_token_id + token_ids_1 + eos_token_id
return output
def get_special_tokens_mask( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False ) -> List[int]: """ Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding special tokens using the tokenizer `prepare_for_model` method. Args: token_ids_0 (`List[int]`): List of IDs. token_ids_1 (`List[int]`, *optional*): Optional second list of IDs for sequence pairs. already_has_special_tokens (`bool`, *optional*, defaults to `False`): Whether or not the token list is already formatted with special tokens for the model. Returns: `List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token. """ if already_has_special_tokens: return super().get_special_tokens_mask( token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True )
bos_token_id = [1] if self.add_bos_token else [] eos_token_id = [1] if self.add_eos_token else []
if token_ids_1 is None: return bos_token_id + ([0] * len(token_ids_0)) + eos_token_id return ( bos_token_id + ([0] * len(token_ids_0)) + eos_token_id + bos_token_id + ([0] * len(token_ids_1)) + eos_token_id )
def create_token_type_ids_from_sequences( self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None ) -> List[int]: """ Creates a mask from the two sequences passed to be used in a sequence-pair classification task. An ALBERT sequence pair mask has the following format: ``` 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 | first sequence | second sequence | ``` if token_ids_1 is None, only returns the first portion of the mask (0s). Args: token_ids_0 (`List[int]`): List of ids. token_ids_1 (`List[int]`, *optional*): Optional second list of IDs for sequence pairs. Returns: `List[int]`: List of [token type IDs](../glossary#token-type-ids) according to the given sequence(s). """ bos_token_id = [self.bos_token_id] if self.add_bos_token else [] eos_token_id = [self.eos_token_id] if self.add_eos_token else []
output = [0] * len(bos_token_id + token_ids_0 + eos_token_id)
if token_ids_1 is not None: output += [1] * len(bos_token_id + token_ids_1 + eos_token_id)
return output
123version https://git-lfs.github.com/spec/v1oid sha256:7d3be68e090a927f31e0e378d7599b15c206dd47e4a73933775a746cc9c1cd91size 1345108123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240{ "add_bos_token": false, "add_eos_token": false, "added_tokens_decoder": { "0": { "content": "<unk>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": true, "special": true }, "1": { "content": "<s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": false, "special": true }, "2": { "content": "</s>", "lstrip": false, "normalized": true, "rstrip": false, "single_word": true, "special": true }, "75858": { "content": "<CLS>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "75859": { "content": "<SEP>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "75860": { "content": "<EOD>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "75861": { "content": "<MASK>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "75862": { "content": "<PAD>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "75863": { "content": "<|im_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "75864": { "content": "<|im_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "75865": { "content": "<|fim_prefix|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "75866": { "content": "<|fim_middle|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "75867": { "content": "<|fim_suffix|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "75868": { "content": "<|fim_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "75869": { "content": "<|endoftext|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "75870": { "content": "<|repo_name|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "75871": { "content": "<|file_sep|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "75872": { "content": "<think>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "75873": { "content": "</think>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "75874": { "content": "<tools>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "75875": { "content": "</tools>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "75876": { "content": "<tool_call>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "75877": { "content": "</tool_call>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "75878": { "content": "<tool_response>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "75879": { "content": "</tool_response>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false } }, "additional_special_tokens": [ "<|CLS|>", "<|SEP|>", "<|EOD|>", "<|MASK|>", "<|PAD|>", "<|fim_prefix|>", "<|fim_middle|>", "<|fim_suffix|>", "<|im_start|>", "<|im_end|>", "<|fim_pad|>", "<|endoftext|>", "<|repo_name|>", "<|file_sep|>" ], "auto_map": { "AutoTokenizer": [ "tokenization_neo.NEOTokenizer", null ] }, "bos_token": "<s>", "chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0].role == 'system' %}\n {{- messages[0].content + '\\n\\n' }}\n {%- else %}\n {{- 'You are IQuest-Coder, a helpful assistant developed by IQuest.' }}\n {%- endif %}\n {{- \"# Tools\\n\\nYou have access to the following functions:\\n\\n<tools>\" }}\n {%- for tool in tools %}\n {%- if tool.type == 'function' and tool.function %}\n {%- set func = tool.function %}\n {%- else %}\n {%- set func = tool %}\n {%- endif %}\n {{- \"\\n<function>\\n<name>\" + func.name + \"</name>\" }}\n {%- if func.description %}\n {{- \"\\n<description>\" + func.description + \"</description>\" }}\n {%- endif %}\n {{- \"\\n<parameters>\" }}\n {%- if func.parameters and func.parameters.properties %}\n {%- for param_name, param_fields in func.parameters.properties.items() %}\n {{- \"\\n<parameter>\" }}\n {{- \"\\n<name>\" + param_name + \"</name>\" }}\n {%- if param_fields.type %}\n {{- \"\\n<type>\" + param_fields.type + \"</type>\" }}\n {%- endif %}\n {%- if param_fields.description %}\n {{- \"\\n<description>\" + param_fields.description + \"</description>\" }}\n {%- endif %}\n {{- \"\\n</parameter>\" }}\n {%- endfor %}\n {%- endif %}\n {{- \"\\n</parameters>\\n</function>\" }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nIf you choose to call a function ONLY reply in the following format:\\n\\n<tool_call>\\n<function=example_function_name>\\n<parameter=example_parameter_1>\\nvalue_1\\n</parameter>\\n</function>\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0].role == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0].content + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are IQuest-Coder, a helpful assistant developed by IQuest.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}\n{%- for message in messages[::-1] %}\n {%- set index = (messages|length - 1) - loop.index0 %}\n {%- if ns.multi_step_tool and message.role == \"user\" and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n{%- endfor %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {%- set content = message.content %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- if message.tool_calls %}\n {%- for tool_call in message.tool_calls %}\n {%- if (loop.first and content) or (not loop.first) %}\n {{- '\\n' }}\n {%- endif %}\n {%- if tool_call.function %}\n {%- set tc = tool_call.function %}\n {%- else %}\n {%- set tc = tool_call %}\n {%- endif %}\n {{- '<tool_call>\\n<function=' + tc.name + '>\\n' }}\n {%- if tc.arguments is string %}\n {%- set args = tc.arguments | fromjson %}\n {%- else %}\n {%- set args = tc.arguments %}\n {%- endif %}\n {%- for arg_name, arg_value in args.items() %}\n {{- '<parameter=' + arg_name + '>\\n' }}\n {%- if arg_value is string %}\n {{- arg_value }}\n {%- else %}\n {{- arg_value | tojson }}\n {%- endif %}\n {{- '\\n</parameter>\\n' }}\n {%- endfor %}\n {{- '</function>\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.first or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}", "clean_up_tokenization_spaces": false, "eos_token": "<|im_end|>", "model_max_length": 131072, "pad_token": "<|endoftext|>", "padding_side": "right", "sp_model_kwargs": {}, "split_special_tokens": false, "tokenizer_class": "NEOTokenizer", "unk_token": "<unk>", "use_fast": false}config.jsonAdded+33
conversion_to_hf.logAdded+109
generation_config.jsonAdded+6
model-00001-of-00004.safetensorsAdded+3
model-00002-of-00004.safetensorsAdded+3
model-00003-of-00004.safetensorsAdded+3
model-00004-of-00004.safetensorsAdded+3
model.safetensors.index.jsonAdded+137
tokenization_neo.pyAdded+246
tokenizer.modelAdded+3
tokenizer_config.jsonAdded+240