Add pytorch, tf version
Browse files- events.out.tfevents.1626033670.t1v-n-a95a71e5-w-0.441100.3.v2 +2 -2
- pytorch_model.bin +3 -0
- src/convert_flax_to_pytorch.py +31 -0
- src/convert_flax_to_tf.py +24 -0
- tf_model.h5 +3 -0
events.out.tfevents.1626033670.t1v-n-a95a71e5-w-0.441100.3.v2
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7663ff60a0b876debfd15a5101a510a59721b473d85bf2e605a223328e96e047
|
| 3 |
+
size 48307053
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cae1f3c7d3627c1b1ce2ebc6991542e88781e525b4ef12041c25900aea411d12
|
| 3 |
+
size 1443523865
|
src/convert_flax_to_pytorch.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
import jax
|
| 5 |
+
import jax.numpy as jnp
|
| 6 |
+
|
| 7 |
+
from transformers import AutoTokenizer
|
| 8 |
+
from transformers import FlaxGPT2LMHeadModel
|
| 9 |
+
from transformers import GPT2LMHeadModel
|
| 10 |
+
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained("../")
|
| 12 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 13 |
+
|
| 14 |
+
model_fx = FlaxGPT2LMHeadModel.from_pretrained("../")
|
| 15 |
+
|
| 16 |
+
# def to_f32(t):
|
| 17 |
+
# return jax.tree_map(lambda x: x.astype(jnp.float32) if x.dtype == jnp.bfloat16 else x, t)
|
| 18 |
+
|
| 19 |
+
# model_fx.params = to_f32(model_fx.params)
|
| 20 |
+
# model_fx.save_pretrained("./fx")
|
| 21 |
+
|
| 22 |
+
model_pt = GPT2LMHeadModel.from_pretrained("../", from_flax=True)
|
| 23 |
+
model_pt.save_pretrained("./pt")
|
| 24 |
+
|
| 25 |
+
input_ids = np.asarray(2 * [128 * [0]], dtype=np.int32)
|
| 26 |
+
input_ids_pt = torch.tensor(input_ids)
|
| 27 |
+
|
| 28 |
+
logits_pt = model_pt(input_ids_pt).logits
|
| 29 |
+
print(logits_pt)
|
| 30 |
+
logits_fx = model_fx(input_ids).logits
|
| 31 |
+
print(logits_fx)
|
src/convert_flax_to_tf.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
import jax
|
| 5 |
+
import jax.numpy as jnp
|
| 6 |
+
|
| 7 |
+
from transformers import AutoTokenizer
|
| 8 |
+
from transformers import GPT2LMHeadModel
|
| 9 |
+
from transformers import TFGPT2LMHeadModel
|
| 10 |
+
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained("../")
|
| 12 |
+
tokenizer.pad_token = tokenizer.eos_token
|
| 13 |
+
|
| 14 |
+
model_pt = GPT2LMHeadModel.from_pretrained("./pt")
|
| 15 |
+
model_tf = TFGPT2LMHeadModel.from_pretrained("./pt", from_pt=True)
|
| 16 |
+
model_tf.save_pretrained("./tf")
|
| 17 |
+
|
| 18 |
+
input_ids = np.asarray(2 * [128 * [0]], dtype=np.int32)
|
| 19 |
+
input_ids_pt = torch.tensor(input_ids)
|
| 20 |
+
|
| 21 |
+
logits_pt = model_pt(input_ids_pt).logits
|
| 22 |
+
print(logits_pt)
|
| 23 |
+
logits_tf = model_tf(input_ids).logits
|
| 24 |
+
print(logits_tf)
|
tf_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dc7ac4bf62ab348f0729b3f0aebd539b072bb75a5bcffb7f5ec7778185f305f2
|
| 3 |
+
size 1418594792
|