lmflow.models.hf_text_regression_model#

Attributes#

Classes#

HFTextRegressionModel

Initializes a HFTextRegressionModel instance.

Module Contents#

lmflow.models.hf_text_regression_model.logger[source]#
class lmflow.models.hf_text_regression_model.HFTextRegressionModel(model_args: lmflow.args.ModelArguments, do_train: bool = False, device='gpu', **kwargs)[source]#

Bases: lmflow.models.text_regression_model.TextRegressionModel, lmflow.models.hf_model_mixin.HFModelMixin, lmflow.models.interfaces.tunable.Tunable

Initializes a HFTextRegressionModel instance.

Parameters:
  • model_args – Model arguments such as model name, path, revision, etc.

  • do_train (bool, default True) – Determines whether to prepare the model for training, including distribtued env, model placement, quantization, lora, etc.

  • args (Optional.) – Positional arguments.

  • kwargs (Optional.) – Keyword arguments.

tokenize(dataset: lmflow.datasets.dataset.Dataset, add_special_tokens=True, *args, **kwargs)[source]#

Tokenize the full dataset.

Parameters:
  • dataset (lmflow.datasets.Dataset.)

  • args (Optional.) – Positional arguments.

  • kwargs (Optional.) – Keyword arguments.

Returns:

The tokenized dataset, without any leading or trailing special tokens (normally they are Begin-Of-Sentence or End-Of-Sentence tokens).

Return type:

tokenized_datasets

inference(inputs, release_gpu: bool = False, use_vllm: bool = False, **kwargs) list[float] | transformers.modeling_outputs.SequenceClassifierOutputWithPast[source]#

Perform generation process of the model.

Parameters:
  • inputs – The sequence used as a prompt for the generation or as model inputs to the model. When using vllm inference, this should be a string or a list of strings. When using normal inference, this should be a tensor.

  • release_gpu (bool, optional) – Whether to release the GPU resource after inference, by default False.

  • use_vllm (bool, optional) – Whether to use VLLM for inference, by default False.

  • kwargs (Optional.) – Keyword arguments.

Returns:

The generated sequence output

Return type:

outputs

prepare_inputs_for_inference(dataset: lmflow.datasets.dataset.Dataset, enable_distributed_inference: bool = False, use_vllm: bool = False, **kwargs) lmflow.datasets.dataset.Dataset | ray.data.Dataset[source]#
static postprocess_inference_outputs(dataset: lmflow.datasets.dataset.Dataset, scores: list[float] | list[list[float]])[source]#
static postprocess_distributed_inference_outputs(dataset: lmflow.datasets.dataset.Dataset, inference_result: list[lmflow.utils.data_utils.RewardModelInferenceResultWithInput])[source]#
save(dir, *args, **kwargs)[source]#

Perform generation process of the model.

Parameters:
  • dir – The directory to save model and tokenizer

  • kwargs (Optional.) – Keyword arguments.