<commit_before>#include "cnn/cnn.h"
#include "cnn/shadow-params.h"
#include "cnn/tensor.h"
#include "cnn/aligned-mem-pool.h"
#include "cnn/model.h"

using namespace std;

namespace cnn {

ShadowParameters::ShadowParameters(const ParameterStorage& p) : h(p.values) {
  h.v = (float*)default_device->mem->malloc(h.d.size() * sizeof(float));
  TensorTools::Zero(h);
}

ShadowParameters::~ShadowParameters() {
  default_device->mem->free(h.v);
}

ShadowLookupParameters::ShadowLookupParameters(const LookupParameterStorage& lp) : h(lp.values) {
  for (auto& t : h) {
    t.v = (float*)default_device->mem->malloc(t.d.size() * sizeof(float));
    TensorTools::Zero(t);
  }
}

ShadowLookupParameters::~ShadowLookupParameters() {
  for (auto& t : h)
    default_device->mem->free(t.v);
}

vector<ShadowParameters> AllocateShadowParameters(const Model& m) {
  vector<ShadowParameters> v;<commit_msg>Remove separate malloc for shadow params<commit_after>#include "cnn/cnn.h"
#include "cnn/shadow-params.h"
#include "cnn/tensor.h"
#include "cnn/aligned-mem-pool.h"
#include "cnn/model.h"

using namespace std;

namespace cnn {

ShadowParameters::ShadowParameters(const ParameterStorage& p) : h(p.values) {
  default_device->allocate_tensor(DeviceMempool::PS, h);
  TensorTools::Zero(h);
}

ShadowParameters::~ShadowParameters() {
  default_device->mem->free(h.v);
}

ShadowLookupParameters::ShadowLookupParameters(const LookupParameterStorage& lp) : h(lp.values) {
  for (auto& t : h) {
    default_device->allocate_tensor(DeviceMempool::PS, t);
    TensorTools::Zero(t);
  }
}

ShadowLookupParameters::~ShadowLookupParameters() {
  for (auto& t : h)
    default_device->mem->free(t.v);
}

vector<ShadowParameters> AllocateShadowParameters(const Model& m) {
  vector<ShadowParameters> v;
{'fraction_non_alphanumeric': 0.1586944288126055, 'fraction_numerical': 0.0, 'mean_word_length': 5.9453125, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4698025', 'n_tokens_mistral': 611, 'n_tokens_neox': 608, 'n_words': 100}