35 assert(src.size(0) >= 0);
36 assert(src.size(1) >= 0);
37 dst.resize(src.size(0), src.size(1));
38 auto accs = src.accessor<S,2>();
39 for (
long i = 0; i < src.size(0); i++)
41 for (
long j = 0; j < src.size(1); j++)
43 dst(i, j) = accs[i][j];
51 const std::vector<torch::Tensor> v = src->all_weights();
62 throw std::runtime_error(
"Unexpected set of weights in LSTM. Must be 4 (fw only) or 8 (fw + bw).");
85 copy_matrix<M, S>(src->U1, dst.
m_U1);
86 copy_vector<V, S>(src->u2, dst.
m_u2);
89 copy_vector<V, S>(src->mlp_head->bias, dst.
m_bias_head);
91 copy_matrix<M, S>(src->mlp_dep->weight, dst.
m_weight_dep);
92 copy_vector<V, S>(src->mlp_dep->bias, dst.
m_bias_dep);
100 copy_vector<V, S>(src->mlp_head->bias, dst.
m_bias_head);
102 copy_matrix<M, S>(src->mlp_dep->weight, dst.
m_weight_dep);
103 copy_vector<V, S>(src->mlp_dep->bias, dst.
m_bias_dep);
107 const int64_t num_labels = src->U.size(0);
108 dst.
m_U.resize(num_labels);
109 for (int64_t l = 0; l < num_labels; ++l)
111 copy_matrix<M, S>(src->U[l], dst.
m_U[l]);
114 copy_vector<V, S>(src->root.reshape({-1}), dst.
m_root);
120 std::shared_ptr<UInt64Dict> sp_uint64_dict = std::dynamic_pointer_cast<UInt64Dict, DictBase>(sp_dict);
121 std::shared_ptr<Char32Dict> sp_char32_dict = std::dynamic_pointer_cast<Char32Dict, DictBase>(sp_dict);
122 assert(sp_uint64_dict || sp_char32_dict);
124 copy_matrix<M, S>(src->weight, tmp);
127 dst.
init(sp_uint64_dict, tmp);
129 else if (sp_char32_dict)
131 dst.
init(sp_char32_dict, tmp);
135 throw std::runtime_error(
"Unknown dict type.");