I found an error in my original memcpy code. You need to multiply the number of elements by the size of the data type:
memcpy(module.named_parameters()["layer"].data<float>(), vector.data(), element_count * sizeof(float));