<commit_before>export { NeuralNet_StageParamsCreator_Base as Base };

import * as Pool from "../../../util/Pool.js";
import * as Recyclable from "../../../util/Recyclable.js";
import * as ValueDesc from "../../../Unpacker/ValueDesc.js";
import * as Stage from "../../Stage.js";
//import { Params } from "../NeuralNet_Params.js";

/**
 * Base class for all NeuralNet.StageParamsCreator.Xxx classes.
 *
 *
 */
class NeuralNet_StageParamsCreator_Base extends Recyclable.Root {

  /**
   * Used as default NeuralNet.StageParamsCreator.Base provider for conforming to Recyclable interface.
   */
  static Pool = new Pool.Root( "NeuralNet.StageParamsCreator.Base.Pool",
    NeuralNet_StageParamsCreator_Base, NeuralNet_StageParamsCreator_Base.setAsConstructor );

  /**
   * @param {Params} neuralNetParams
   *   The NeuralNet.Params object which provides basic parameters. It will be referenced (i.e. not cloned, not owned, not released)
   * by this NeuralNet.StageParamsCreator.Base onject.
   */
  constructor( neuralNetParams ) {
    super();
    NeuralNet_StageParamsCreator_Base.setAsConstructor_self.call( this, neuralNetParams );
  }

  /** @override */
  static setAsConstructor( neuralNetParams ) {
    super.setAsConstructor();
    NeuralNet_StageParamsCreator_Base.setAsConstructor_self.call( this, neuralNetParams );
    return this;
  }

  /** @override */
  static setAsConstructor_self( neuralNetParams ) {
    this.neuralNetParams = neuralNetParams;
  }

  /** @override */
  disposeResources() {
    this.blockFinalParams_dispose();

    this.bKeepInputTensor = undefined;
    this.nActivationId = undefined;
    this.nSqueezeExcitationChannelCountDivisor = undefined;
    this.depthwiseFilterWidth = undefined;
    this.depthwiseFilterHeight = undefined;
    this.bPointwise1 = undefined;
    this.blockCountRequested = undefined;
    this.nConvStageTypeId = undefined;
    this.input_channelCount = undefined;
    this.input_width = undefined;
    this.input_height = undefined;

    this.stageCount = undefined; // How many stage should be in the neuralNet.

    this.neuralNetParams = undefined; // Just nullify it. Do not release it here.

    super.disposeResources();
  }

  /** */
  blockFinalParams_dispose() {
    if ( this.blockFinalParams ) {
      this.blockFinalParams.disposeResources_and_recycleToPool();
      this.blockFinalParams = null;
    }
  }

  /** Called to determine stageCount.
    *
    * Sub-class could override this method to adjust data members.
    */
  determine_stageCount() {
    let neuralNetParams = this.neuralNetParams;

//!!! (2022/08/17 Remarked) determined by NeuralNet_StageParamsCreator_Base.
//    this.stageCount = neuralNetParams.stageCountRequested; // By default, the stage count is just the requested original stage count.


    // Because every stage will double output channel count, find out stageCount
    // so that the stageLast's output channel count is (a little) larger than
    // the requested output_channelCount.
    let expandFactor = Math.ceil( output_channelCount / vocabularyChannelCount );
    this.stageCount =  Math.max( 1, Math.ceil( Math.log2( expandFactor ) ) );
  }

  /**
   * Called before stage0 is about to be created.
   */
  configTo_beforeStage0() {
    let neuralNetParams = this.neuralNetParams;

    this.input_height = neuralNetParams.input_height;
    this.input_width = neuralNetParams.input_width;

    // The channel count is expanded by prefix embedding layer.
    this.input_channelCount
      = neuralNetParams.input_channelCount * neuralNetParams.vocabularyChannelCount;

    this.nConvStageTypeId = neuralNetParams.nConvStageTypeId;

    this.blockCountRequested = neuralNetParams.blockCountRequested;
    this.bPointwise1 = true; // Always use pointwise1.

    this.depthwiseFilterHeight = 3; // Always use ( 3 * 3 ) depthwise filter.
    this.depthwiseFilterWidth = 3;<commit_msg>stageCount<commit_after>export { NeuralNet_StageParamsCreator_Base as Base };

import * as Pool from "../../../util/Pool.js";
import * as Recyclable from "../../../util/Recyclable.js";
import * as ValueDesc from "../../../Unpacker/ValueDesc.js";
import * as Stage from "../../Stage.js";
//import { Params } from "../NeuralNet_Params.js";

/**
 * Base class for all NeuralNet.StageParamsCreator.Xxx classes.
 *
 *
 */
class NeuralNet_StageParamsCreator_Base extends Recyclable.Root {

  /**
   * Used as default NeuralNet.StageParamsCreator.Base provider for conforming to Recyclable interface.
   */
  static Pool = new Pool.Root( "NeuralNet.StageParamsCreator.Base.Pool",
    NeuralNet_StageParamsCreator_Base, NeuralNet_StageParamsCreator_Base.setAsConstructor );

  /**
   * @param {Params} neuralNetParams
   *   The NeuralNet.Params object which provides basic parameters. It will be referenced (i.e. not cloned, not owned, not released)
   * by this NeuralNet.StageParamsCreator.Base onject.
   */
  constructor( neuralNetParams ) {
    super();
    NeuralNet_StageParamsCreator_Base.setAsConstructor_self.call( this, neuralNetParams );
  }

  /** @override */
  static setAsConstructor( neuralNetParams ) {
    super.setAsConstructor();
    NeuralNet_StageParamsCreator_Base.setAsConstructor_self.call( this, neuralNetParams );
    return this;
  }

  /** @override */
  static setAsConstructor_self( neuralNetParams ) {
    this.neuralNetParams = neuralNetParams;
  }

  /** @override */
  disposeResources() {
    this.blockFinalParams_dispose();

    this.bKeepInputTensor = undefined;
    this.nActivationId = undefined;
    this.nSqueezeExcitationChannelCountDivisor = undefined;
    this.depthwiseFilterWidth = undefined;
    this.depthwiseFilterHeight = undefined;
    this.bPointwise1 = undefined;
    this.blockCountRequested = undefined;
    this.nConvStageTypeId = undefined;
    this.input_channelCount = undefined;
    this.input_width = undefined;
    this.input_height = undefined;

    this.stageCount = undefined; // How many stage should be in the neuralNet.

    this.neuralNetParams = undefined; // Just nullify it. Do not release it here.

    super.disposeResources();
  }

  /** */
  blockFinalParams_dispose() {
    if ( this.blockFinalParams ) {
      this.blockFinalParams.disposeResources_and_recycleToPool();
      this.blockFinalParams = null;
    }
  }

  /** Called to determine stageCount.
    *
    * Sub-class could override this method to adjust data members.
    */
  determine_stageCount() {
    let neuralNetParams = this.neuralNetParams;

//!!! (2022/08/17 Remarked) determined by NeuralNet_StageParamsCreator_Base.
//    this.stageCount = neuralNetParams.stageCountRequested; // By default, the stage count is just the requested original stage count.


    // Because every stage will double output channel count, find out stageCount
    // so that the stageLast's output channel count is (a little) larger than
    // the requested output_channelCount.
    {
      let expandFactor = Math.ceil(
        neuralNetParams.output_channelCount / neuralNetParams.vocabularyChannelCount );

      this.stageCount = Math.max(
        1, // (at least, one stage.)
        Math.ceil( Math.log2( expandFactor ) )
      );
    }
  }

  /**
   * Called before stage0 is about to be created.
   */
  configTo_beforeStage0() {
    let neuralNetParams = this.neuralNetParams;

    this.input_height = neuralNetParams.input_height;
    this.input_width = neuralNetParams.input_width;

    // The channel count is expanded by prefix embedding layer.
    this.input_channelCount
      = neuralNetParams.input_channelCount * neuralNetParams.vocabularyChannelCount;

    this.nConvStageTypeId = neuralNetParams.nConvStageTypeId;

    this.blockCountRequested = neuralNetParams.blockCountRequested;
    this.bPointwise1 = true; // Always use pointwise1.

    this.depthwiseFilterHeight = 3; // Always use ( 3 * 3 ) depthwise filter.
    this.depthwiseFilterWidth = 3;
{'fraction_non_alphanumeric': 0.09917564996829423, 'fraction_numerical': 0.004819277108433735, 'mean_word_length': 3.5400115141047785, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3527075', 'n_tokens_mistral': 2346, 'n_tokens_neox': 2266, 'n_words': 551}