ijktech-jk commited on
Commit
6829cc9
Β·
verified Β·
1 Parent(s): 6b0ac00

Add README with project details

Browse files
Files changed (1) hide show
  1. README.md +55 -1
README.md CHANGED
@@ -5,6 +5,7 @@ tags:
5
  - byte-tokenization
6
  - mobile
7
  - embedded
 
8
  license: cc-by-nc-4.0
9
  datasets:
10
  - custom
@@ -74,10 +75,63 @@ The tokenizer is byte-level, compatible with AutoTokenizer from Hugging Face:
74
  tokenizer = AutoTokenizer.from_pretrained("ijktech/ByteGPT-small")
75
  ```
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  ## πŸ“œ License
78
  πŸ“ **CC-BY-NC-4.0**: Free for non-commercial use.
79
 
80
- πŸ’Ό **Commercial Use**: Contact IJK Technology Ltd for licensing.
81
 
82
  ## πŸ› οΈ About IJK Technology Ltd
83
  IJK Technology Ltd (IJKTech) develops innovative machine learning models optimized for on-device inference. Our focus is on efficiency, privacy, and usability across mobile and embedded platforms.
 
5
  - byte-tokenization
6
  - mobile
7
  - embedded
8
+ - onnx
9
  license: cc-by-nc-4.0
10
  datasets:
11
  - custom
 
75
  tokenizer = AutoTokenizer.from_pretrained("ijktech/ByteGPT-small")
76
  ```
77
 
78
+ ### ONNX
79
+
80
+ The model is also available in ONNX format, and can be used with the ONNX Runtime:
81
+
82
+ ```python
83
+ import onnxruntime as ort
84
+ import numpy as np
85
+
86
+ # Create ONNX Runtime session
87
+ ort_session = ort.InferenceSession("model.onnx")
88
+
89
+ # Helper function to generate text using the ONNX model
90
+ def generate_with_onnx(prompt_ids, max_new_tokens=50, temperature=1.0):
91
+ input_ids = prompt_ids.clone()
92
+
93
+ for _ in range(max_new_tokens):
94
+ # Get the last block_size tokens if input is too long
95
+ if input_ids.shape[1] > model.block_size:
96
+ input_ids = input_ids[:, -model.block_size:]
97
+
98
+ # Run inference
99
+ ort_inputs = {
100
+ 'input': input_ids.cpu().numpy()
101
+ }
102
+ logits = ort_session.run(None, ort_inputs)[0]
103
+
104
+ # Get predictions for the next token
105
+ logits = torch.from_numpy(logits)
106
+ logits = logits[:, -1, :] # Only take the last token's predictions
107
+
108
+ # Apply temperature
109
+ if temperature != 1.0:
110
+ logits = logits / temperature
111
+
112
+ # Sample from the distribution
113
+ probs = torch.nn.functional.softmax(logits, dim=-1)
114
+ next_token = torch.multinomial(probs, num_samples=1)
115
+
116
+ # Append the new token
117
+ input_ids = torch.cat([input_ids, next_token], dim=1)
118
+
119
+ return input_ids
120
+
121
+ # Test the generation
122
+ prompt = "Hello"
123
+ prompt_ids = tok(prompt, return_tensors="pt")["input_ids"]
124
+ generated_ids = generate_with_onnx(prompt_ids)
125
+ generated_text = tok.decode(generated_ids[0], skip_special_tokens=True)
126
+ print(f"Generated text: {generated_text}")
127
+ #Generated text: Hello everyone!
128
+ #A dinner is only available for St. Loui
129
+ ```
130
+
131
  ## πŸ“œ License
132
  πŸ“ **CC-BY-NC-4.0**: Free for non-commercial use.
133
 
134
+ πŸ’Ό **Commercial Use**: Contact IJK Technology Ltd for licensing at [james@ijktech.com](mailto:[email protected]).
135
 
136
  ## πŸ› οΈ About IJK Technology Ltd
137
  IJK Technology Ltd (IJKTech) develops innovative machine learning models optimized for on-device inference. Our focus is on efficiency, privacy, and usability across mobile and embedded platforms.