初始化项目,由ModelHub XC社区提供模型
Model: transformers-community/custom_generate_bad_requirements Source: Original Platform
This commit is contained in:
36
.gitattributes
vendored
Normal file
36
.gitattributes
vendored
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.model filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.npy filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.npz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pickle filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pkl filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||||
|
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.json filter=lfs diff=lfs merge=lfs -text
|
||||||
42
README.md
Normal file
42
README.md
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
---
|
||||||
|
library_name: transformers
|
||||||
|
tags: [custom_generate]
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
## Description
|
||||||
|
Example repository used to document `generate` from the hub.
|
||||||
|
|
||||||
|
⚠️ this custom generation method has an impossible requirement and is meant to crash. If you try to run it, you should see something like
|
||||||
|
```
|
||||||
|
ValueError: Missing requirements for `transformers-community/custom_generate_bad_requirements`:
|
||||||
|
foo (installed: None)
|
||||||
|
bar==0.0.0 (installed: None)
|
||||||
|
torch>=99.0 (installed: 2.6.0+cu126)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Base model
|
||||||
|
`Qwen/Qwen2.5-0.5B-Instruct`
|
||||||
|
|
||||||
|
## Model compatibility
|
||||||
|
Most models. More specifically, any `transformer` LLM/VLM trained for causal language modeling.
|
||||||
|
|
||||||
|
## Additional Arguments
|
||||||
|
`left_padding` (`int`, *optional*): number of padding tokens to add before the provided input
|
||||||
|
|
||||||
|
## Output Type changes
|
||||||
|
(none)
|
||||||
|
|
||||||
|
## Example usage
|
||||||
|
|
||||||
|
```py
|
||||||
|
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||||||
|
|
||||||
|
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct")
|
||||||
|
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct", device_map="auto")
|
||||||
|
|
||||||
|
inputs = tokenizer(["The quick brown"], return_tensors="pt").to(model.device)
|
||||||
|
gen_out = model.generate(**inputs, custom_generate="transformers-community/custom_generate_bad_requirements", trust_remote_code=True)
|
||||||
|
# You should get an exception regarding missing requirements
|
||||||
|
```
|
||||||
|
|
||||||
BIN
added_tokens.json
(Stored with Git LFS)
Normal file
BIN
added_tokens.json
(Stored with Git LFS)
Normal file
Binary file not shown.
54
chat_template.jinja
Normal file
54
chat_template.jinja
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
{%- if tools %}
|
||||||
|
{{- '<|im_start|>system\n' }}
|
||||||
|
{%- if messages[0]['role'] == 'system' %}
|
||||||
|
{{- messages[0]['content'] }}
|
||||||
|
{%- else %}
|
||||||
|
{{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
|
||||||
|
{%- endif %}
|
||||||
|
{{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
|
||||||
|
{%- for tool in tools %}
|
||||||
|
{{- "\n" }}
|
||||||
|
{{- tool | tojson }}
|
||||||
|
{%- endfor %}
|
||||||
|
{{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
|
||||||
|
{%- else %}
|
||||||
|
{%- if messages[0]['role'] == 'system' %}
|
||||||
|
{{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
|
||||||
|
{%- else %}
|
||||||
|
{{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
|
||||||
|
{%- endif %}
|
||||||
|
{%- endif %}
|
||||||
|
{%- for message in messages %}
|
||||||
|
{%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
|
||||||
|
{{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
|
||||||
|
{%- elif message.role == "assistant" %}
|
||||||
|
{{- '<|im_start|>' + message.role }}
|
||||||
|
{%- if message.content %}
|
||||||
|
{{- '\n' + message.content }}
|
||||||
|
{%- endif %}
|
||||||
|
{%- for tool_call in message.tool_calls %}
|
||||||
|
{%- if tool_call.function is defined %}
|
||||||
|
{%- set tool_call = tool_call.function %}
|
||||||
|
{%- endif %}
|
||||||
|
{{- '\n<tool_call>\n{"name": "' }}
|
||||||
|
{{- tool_call.name }}
|
||||||
|
{{- '", "arguments": ' }}
|
||||||
|
{{- tool_call.arguments | tojson }}
|
||||||
|
{{- '}\n</tool_call>' }}
|
||||||
|
{%- endfor %}
|
||||||
|
{{- '<|im_end|>\n' }}
|
||||||
|
{%- elif message.role == "tool" %}
|
||||||
|
{%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
|
||||||
|
{{- '<|im_start|>user' }}
|
||||||
|
{%- endif %}
|
||||||
|
{{- '\n<tool_response>\n' }}
|
||||||
|
{{- message.content }}
|
||||||
|
{{- '\n</tool_response>' }}
|
||||||
|
{%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
|
||||||
|
{{- '<|im_end|>\n' }}
|
||||||
|
{%- endif %}
|
||||||
|
{%- endif %}
|
||||||
|
{%- endfor %}
|
||||||
|
{%- if add_generation_prompt %}
|
||||||
|
{{- '<|im_start|>assistant\n' }}
|
||||||
|
{%- endif %}
|
||||||
3
config.json
Normal file
3
config.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:99af74a37bd58e5fc656b7c5d597b0369a80b7d11ae29328c84961d10fa274e7
|
||||||
|
size 687
|
||||||
32
custom_generate/generate.py
Normal file
32
custom_generate/generate.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import torch
|
||||||
|
|
||||||
|
def generate(model, input_ids, generation_config=None, left_padding=None, **kwargs):
|
||||||
|
|
||||||
|
print("✨ using a custom generation method ✨")
|
||||||
|
|
||||||
|
generation_config = generation_config or model.generation_config # default to the model generation config
|
||||||
|
cur_length = input_ids.shape[1]
|
||||||
|
max_length = generation_config.max_length or cur_length + generation_config.max_new_tokens
|
||||||
|
|
||||||
|
# Example of custom argument: add `left_padding` (integer) pad tokens before the prompt
|
||||||
|
if left_padding is not None:
|
||||||
|
if not isinstance(left_padding, int) or left_padding < 0:
|
||||||
|
raise ValueError(f"left_padding must be an integer larger than 0, but is {left_padding}")
|
||||||
|
|
||||||
|
pad_token = kwargs.pop("pad_token", None) or generation_config.pad_token_id or model.config.pad_token_id
|
||||||
|
if pad_token is None:
|
||||||
|
raise ValueError("pad_token is not defined")
|
||||||
|
batch_size = input_ids.shape[0]
|
||||||
|
pad_tensor = torch.full(size=(batch_size, left_padding), fill_value=pad_token).to(input_ids.device)
|
||||||
|
input_ids = torch.cat((pad_tensor, input_ids), dim=1)
|
||||||
|
cur_length = input_ids.shape[1]
|
||||||
|
|
||||||
|
# Simple greedy decoding loop
|
||||||
|
while cur_length < max_length:
|
||||||
|
logits = model(input_ids).logits
|
||||||
|
next_token_logits = logits[:, -1, :]
|
||||||
|
next_tokens = torch.argmax(next_token_logits, dim=-1)
|
||||||
|
input_ids = torch.cat((input_ids, next_tokens[:, None]), dim=-1)
|
||||||
|
cur_length += 1
|
||||||
|
|
||||||
|
return input_ids
|
||||||
3
custom_generate/requirements.txt
Normal file
3
custom_generate/requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
foo
|
||||||
|
bar==0.0.0
|
||||||
|
torch>=99.0
|
||||||
3
generation_config.json
Normal file
3
generation_config.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:fded30552c15d28209902e114abb9e37d67e0947af31de7ac4ccce23209236ac
|
||||||
|
size 247
|
||||||
151388
merges.txt
Normal file
151388
merges.txt
Normal file
File diff suppressed because it is too large
Load Diff
3
model.safetensors
Normal file
3
model.safetensors
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:ff208332ee07c8e0538cc753e9b4a0ee6c42b191f878aa21bae2e667fa9c725b
|
||||||
|
size 1976163472
|
||||||
BIN
special_tokens_map.json
(Stored with Git LFS)
Normal file
BIN
special_tokens_map.json
(Stored with Git LFS)
Normal file
Binary file not shown.
3
tokenizer.json
Normal file
3
tokenizer.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:9c5ae00e602b8860cbd784ba82a8aa14e8feecec692e7076590d014d7b7fdafa
|
||||||
|
size 11421896
|
||||||
3
tokenizer_config.json
Normal file
3
tokenizer_config.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:0a04a9d7d4a62b28482bdfe726c122756de85714fb64166ace92ae75b8f57614
|
||||||
|
size 4686
|
||||||
BIN
vocab.json
(Stored with Git LFS)
Normal file
BIN
vocab.json
(Stored with Git LFS)
Normal file
Binary file not shown.
Reference in New Issue
Block a user