Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,89 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# FeynModel V 0.1
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+

|
| 5 |
+
|
| 6 |
+
# how to use
|
| 7 |
+
|
| 8 |
+
```python
|
| 9 |
+
from transformers import AutoProcessor, AutoModelForCausalLM
|
| 10 |
+
model_id='Imagroune/feynmodel'
|
| 11 |
+
processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)
|
| 12 |
+
model = AutoModelForCausalLM.from_pretrained(model_id,trust_remote_code=True)
|
| 13 |
+
model.to('cuda')
|
| 14 |
+
```
|
| 15 |
+
|
| 16 |
+
# LLM Inference
|
| 17 |
+
|
| 18 |
+
```python
|
| 19 |
+
|
| 20 |
+
input_text = "<start_of_turn>user\nCombien d'helicoptère un humain adulte peut manger en un seul repas?.<end_of_turn> <start_of_turn>model\n"
|
| 21 |
+
input_ids = processor.tokenizer(input_text, return_tensors="pt").to("cuda")
|
| 22 |
+
|
| 23 |
+
# Génération du texte en mode streaming
|
| 24 |
+
max_length = input_ids.input_ids.shape[1] + 1024 # Longueur maximale totale
|
| 25 |
+
stream_output = [] # Liste pour stocker le flux de sortie
|
| 26 |
+
|
| 27 |
+
# Génération et affichage en mode streaming
|
| 28 |
+
for output in model.generate(input_ids=input_ids.input_ids,max_length=max_length, do_sample=True, temperature=0.7):
|
| 29 |
+
decoded_output = processor.tokenizer.decode(output, skip_special_tokens=True)
|
| 30 |
+
stream_output.append(decoded_output)
|
| 31 |
+
print(decoded_output, end="", flush=True)
|
| 32 |
+
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
# Vision Inference
|
| 36 |
+
|
| 37 |
+
```python
|
| 38 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, StoppingCriteria, StoppingCriteriaList
|
| 39 |
+
|
| 40 |
+
class PrintTokensStoppingCriteria(StoppingCriteria):
|
| 41 |
+
def __init__(self, tokenizer):
|
| 42 |
+
self.tokenizer = tokenizer
|
| 43 |
+
|
| 44 |
+
def __call__(self, input_ids, scores, **kwargs):
|
| 45 |
+
# Decode the last generated token and print it
|
| 46 |
+
last_token_id = input_ids[0, -1].item()
|
| 47 |
+
token = self.tokenizer.decode([last_token_id], skip_special_tokens=True)
|
| 48 |
+
print(token, end='', flush=True)
|
| 49 |
+
|
| 50 |
+
# Continue generating tokens until a stopping condition is met
|
| 51 |
+
# Return True to stop, False to continue
|
| 52 |
+
return False
|
| 53 |
+
stopping_criteria = PrintTokensStoppingCriteria(processor.tokenizer)
|
| 54 |
+
|
| 55 |
+
from PIL import Image
|
| 56 |
+
import requests
|
| 57 |
+
input_text = "<start_of_turn>user\n what is this ?<end_of_turn>\n<start_of_turn>model"
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/car.jpg?download=true"
|
| 61 |
+
image = Image.open(requests.get(url, stream=True).raw)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
input_text="""<start_of_turn>user
|
| 65 |
+
Create a concise caption that accurately describes the main elements in the image provided
|
| 66 |
+
<end_of_turn>
|
| 67 |
+
<start_of_turn>model
|
| 68 |
+
|
| 69 |
+
"""
|
| 70 |
+
inputs = processor(text=input_text, images=image, return_tensors="pt")
|
| 71 |
+
inputs = {key: value.cuda() for key, value in inputs.items()}
|
| 72 |
+
|
| 73 |
+
image
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+

|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
```python
|
| 81 |
+
|
| 82 |
+
max_length =inputs['input_ids'].shape[1] + 1024 # Longueur maximale totale
|
| 83 |
+
stream_output = [] # Liste pour stocker le flux de sortie
|
| 84 |
+
# Génération et affichage en mode streaming
|
| 85 |
+
ret= model.generate(inputs['input_ids'], pixel_values=inputs['pixel_values'],stopping_criteria=StoppingCriteriaList([stopping_criteria]),max_length=2048, do_sample=True, temperature=0.7)
|
| 86 |
+
|
| 87 |
+
# An older, green car sits parked on the curb in front of a building.
|
| 88 |
+
|
| 89 |
+
```
|