Parse GPT hyperparameters.
(config, prefix, outfile, use_f16)
| 80 | |
| 81 | |
| 82 | def parse_hparams(config, prefix, outfile, use_f16): |
| 83 | """Parse GPT hyperparameters.""" |
| 84 | hparams = config[f"{prefix}_config"] |
| 85 | |
| 86 | outfile.write(struct.pack("i", hparams["num_layers"])) |
| 87 | outfile.write(struct.pack("i", hparams["num_heads"])) |
| 88 | outfile.write(struct.pack("i", hparams["hidden_size"])) |
| 89 | outfile.write(struct.pack("i", hparams["block_size"])) |
| 90 | |
| 91 | # trick: for fine model, we need to set the bias flag to true, since there are |
| 92 | # bias for the layer norm (to refactor) |
| 93 | bias = True if prefix == "fine_acoustics" else hparams["bias"] |
| 94 | outfile.write(struct.pack("i", int(bias))) |
| 95 | |
| 96 | outfile.write( |
| 97 | struct.pack("ii", hparams["input_vocab_size"], hparams["output_vocab_size"]) |
| 98 | ) |
| 99 | |
| 100 | n_lm_heads, n_wtes = None, None |
| 101 | try: |
| 102 | # only for fine text model |
| 103 | n_lm_heads = hparams["n_codes_total"] - hparams["n_codes_given"] |
| 104 | n_wtes = hparams["n_codes_total"] |
| 105 | except KeyError: |
| 106 | n_lm_heads, n_wtes = 1, 1 |
| 107 | |
| 108 | ftype = int(use_f16) |
| 109 | |
| 110 | outfile.write(struct.pack("iii", n_lm_heads, n_wtes, ftype)) |
| 111 | |
| 112 | |
| 113 | def parse_codec_model_weights(checkpoint, outfile, use_f16): |