Fix typos (#10483)
This commit is contained in:
@@ -72,7 +72,7 @@ PaddleNLP 使用 [Git 分支模型](http://nvie.com/posts/a-successful-git-branc
|
||||
类似于以下内容:
|
||||
|
||||
```text
|
||||
➜ (my-virtual-env) git commit -m "commiting my cool feature"
|
||||
➜ (my-virtual-env) git commit -m "committing my cool feature"
|
||||
black....................................................................Passed
|
||||
isort....................................................................Passed
|
||||
flake8...................................................................Passed
|
||||
@@ -91,7 +91,7 @@ PaddleNLP 使用 [Git 分支模型](http://nvie.com/posts/a-successful-git-branc
|
||||
但大多数时候事情并没有那么顺利。当您的代码或文档不符合标准时,`pre-commit` 检查将失败。
|
||||
|
||||
```text
|
||||
➜ (my-virtual-env) git commit -m "commiting my cool feature"
|
||||
➜ (my-virtual-env) git commit -m "committing my cool feature"
|
||||
black....................................................................Passed
|
||||
isort....................................................................Failed
|
||||
- hook id: isort
|
||||
|
||||
@@ -725,7 +725,7 @@ void MoeGemmRunner<T, WeightType>::run_gemm<EpilogueTag>(
|
||||
gemmConfigManager.addBestConfig(gemmId, profile_total_rows, best_config);
|
||||
chosen_config = best_config;
|
||||
} else {
|
||||
PADDLE_FATAL("[MoE Configure Search] find no one avaliable config.");
|
||||
PADDLE_FATAL("[MoE Configure Search] find no one available config.");
|
||||
}
|
||||
}
|
||||
dispatch_to_arch<EpilogueTag>(A,
|
||||
|
||||
@@ -35,7 +35,7 @@ if "datasets" in sys.modules.keys():
|
||||
|
||||
logger.warning(
|
||||
"Detected that datasets module was imported before paddlenlp. "
|
||||
"This may cause PaddleNLP datasets to be unavalible in intranet. "
|
||||
"This may cause PaddleNLP datasets to be unavailable in intranet. "
|
||||
"Please import paddlenlp before datasets module to avoid download issues"
|
||||
)
|
||||
import paddle
|
||||
|
||||
@@ -436,7 +436,7 @@ class CharInsert(BaseAugment):
|
||||
return sentences
|
||||
|
||||
def _generate_sequence(self, output_seq_tokens, aug_tokens, p):
|
||||
"""Genearte the sequences according to the mapping list"""
|
||||
"""Generate the sequences according to the mapping list"""
|
||||
for aug_token in aug_tokens:
|
||||
idx, token = aug_token
|
||||
if p == 0:
|
||||
|
||||
@@ -33,9 +33,9 @@ __all__ = [
|
||||
class SentenceGenerate:
|
||||
"""
|
||||
SentenceGenerate is a sentence-level data augmentation strategy
|
||||
that generates simialr sentences according to the input sequence.
|
||||
The strattegy first generates several sentences, and then chooses
|
||||
the top n simialr sentences by the model.
|
||||
that generates similar sentences according to the input sequence.
|
||||
The strategy first generates several sentences, and then chooses
|
||||
the top n similar sentences by the model.
|
||||
|
||||
Args:
|
||||
model_name (str):
|
||||
@@ -82,7 +82,7 @@ class SentenceGenerate:
|
||||
|
||||
@paddle.no_grad()
|
||||
def _generate_similar_sentence(self, sequence, model, tokenizer):
|
||||
"""Generates generate_n similar sentences from the provided sequence, and chooose the best create_n similar sentences."""
|
||||
"""Generates generate_n similar sentences from the provided sequence, and choose the best create_n similar sentences."""
|
||||
|
||||
# Generate generate_n similar sentences
|
||||
generated_sequences = [sequence]
|
||||
@@ -134,7 +134,7 @@ class SentenceSummarize:
|
||||
token probabilities in the "sampling" strategy. Default to 1.0,
|
||||
which means no effect.
|
||||
use_fp16_decoding: (bool): Whether to use fp16 for decoding.
|
||||
Only works when faster entry is avalible. Default to False.
|
||||
Only works when faster entry is available. Default to False.
|
||||
kwargs (dict): Additional keyword arguments refer to ..taskflow.text_summarization.TextSummarization
|
||||
"""
|
||||
|
||||
@@ -337,8 +337,8 @@ class SentenceBackTranslate:
|
||||
class SentenceBackTranslateAPI:
|
||||
"""
|
||||
SentenceBackTranslateAPI is a sentence-level data augmentation strategy
|
||||
that translates the input sequence into one langugage, and backtranslate
|
||||
back into the sourche language by baidu translate api.
|
||||
that translates the input sequence into one language, and back-translate
|
||||
back into the source language by baidu translate api.
|
||||
|
||||
Args:
|
||||
src_lang (str):
|
||||
|
||||
@@ -170,7 +170,7 @@ class WordSubstitute(BaseAugment):
|
||||
return substitute_dict
|
||||
|
||||
def _generate_sequence(self, output_seq_tokens, aug_tokens):
|
||||
"""Genearte the sequences according to the mapping list"""
|
||||
"""Generate the sequences according to the mapping list"""
|
||||
for aug_token in aug_tokens:
|
||||
idx, token = aug_token
|
||||
output_seq_tokens[int(idx)] = token
|
||||
@@ -503,7 +503,7 @@ class WordInsert(BaseAugment):
|
||||
return sentences
|
||||
|
||||
def _generate_sequence(self, output_seq_tokens, aug_tokens, p):
|
||||
"""Genearte the sequences according to the mapping list"""
|
||||
"""Generate the sequences according to the mapping list"""
|
||||
for aug_token in aug_tokens:
|
||||
idx, token = aug_token
|
||||
if p == 0:
|
||||
|
||||
@@ -50,8 +50,8 @@ Args:
|
||||
- text_column (string, required): Name of the column that contains the input text.
|
||||
- label_column (string, required): Name of the column that contains the target variable to predict.
|
||||
- language (string, required): language of the text
|
||||
- metric_for_best_model (string, optional): the name of the metrc for selecting the best model.
|
||||
- greater_is_better (bool, optional): Whether better models should have a greater metric or not. Use in conjuction with `metric_for_best_model`.
|
||||
- metric_for_best_model (string, optional): the name of the metric for selecting the best model.
|
||||
- greater_is_better (bool, optional): Whether better models should have a greater metric or not. Use in conjunction with `metric_for_best_model`.
|
||||
- problem_type (str, optional): Select among ["multi_class", "multi_label"] based on the nature of your problem
|
||||
- output_dir (str, optional): Output directory for the experiments, defaults to "autpnlp_results"
|
||||
- verbosity: (int, optional): controls the verbosity of the run. Defaults to 1, which let the workers log to the driver.To reduce the amount of logs, use verbosity > 0 to set stop the workers from logging to the driver.
|
||||
|
||||
@@ -45,7 +45,7 @@ class AutoTrainerBase(metaclass=ABCMeta):
|
||||
eval_dataset (Dataset, required): Evaluation dataset, must contains the 'text_column' and 'label_column' specified below
|
||||
language (string, required): language of the text
|
||||
metric_for_best_model (string, optional): the name of the metric for selecting the best model.
|
||||
greater_is_better (bool, required): Whether better models should have a greater metric or not. Use in conjuction with `metric_for_best_model`.
|
||||
greater_is_better (bool, required): Whether better models should have a greater metric or not. Use in conjunction with `metric_for_best_model`.
|
||||
output_dir (str, optional): Output directory for the experiments, defaults to "autpnlp_results"
|
||||
verbosity: (int, optional): controls the verbosity of the run. Defaults to 1, which let the workers log to the driver.To reduce the amount of logs,
|
||||
use verbosity > 0 to set stop the workers from logging to the driver.
|
||||
|
||||
@@ -59,8 +59,8 @@ class AutoTrainerForTextClassification(AutoTrainerBase):
|
||||
eval_dataset (Dataset, required): Evaluation dataset, must contains the 'text_column' and 'label_column' specified below
|
||||
text_column (string, required): Name of the column that contains the input text.
|
||||
label_column (string, required): Name of the column that contains the target variable to predict.
|
||||
metric_for_best_model (string, optional): the name of the metrc for selecting the best model. Default to 'eval_accuracy'.
|
||||
greater_is_better (bool, optional): Whether better models should have a greater metric or not. Use in conjuction with `metric_for_best_model`.
|
||||
metric_for_best_model (string, optional): the name of the metric for selecting the best model. Default to 'eval_accuracy'.
|
||||
greater_is_better (bool, optional): Whether better models should have a greater metric or not. Use in conjunction with `metric_for_best_model`.
|
||||
problem_type (str, optional): Select among ["multi_class", "multi_label"] based on the nature of your problem
|
||||
kwargs (dict, optional): Additional keyword arguments passed along to the specific task.
|
||||
language (string, required): language of the text.
|
||||
@@ -639,7 +639,7 @@ class AutoTrainerForTextClassification(AutoTrainerBase):
|
||||
f"Taskflow config saved to {export_path}. You can use the Taskflow config to create a Taskflow instance for inference"
|
||||
)
|
||||
|
||||
logger.info(f"Exported trial_id: {trial_id} to export_path: {export_path} sucessfully!")
|
||||
logger.info(f"Exported trial_id: {trial_id} to export_path: {export_path} successfully!")
|
||||
|
||||
if os.path.exists(self.training_path):
|
||||
logger.info("Removing training checkpoints to conserve disk space")
|
||||
|
||||
@@ -29,10 +29,10 @@ __all__ = ["to_tensor", "to_vocab_buffer", "FasterTokenizer"]
|
||||
def to_tensor(string_values, name="text"):
|
||||
"""
|
||||
Create the tensor that the value holds the list of string.
|
||||
NOTICE: The value will be holded in the cpu place.
|
||||
NOTICE: The value will be held in the cpu place.
|
||||
|
||||
Args:
|
||||
string_values(list[string]): The value will be setted to the tensor.
|
||||
string_values(list[string]): The value will be set to the tensor.
|
||||
name(string): The name of the tensor.
|
||||
"""
|
||||
tensor = paddle.Tensor(core.VarDesc.VarType.STRING, [], name, core.VarDesc.VarType.STRINGS, False)
|
||||
@@ -43,7 +43,7 @@ def to_tensor(string_values, name="text"):
|
||||
def to_vocab_buffer(vocab_dict, name):
|
||||
"""
|
||||
Create the tensor that the value holds the map, the type of key is the string.
|
||||
NOTICE: The value will be holded in the cpu place.
|
||||
NOTICE: The value will be held in the cpu place.
|
||||
|
||||
Args:
|
||||
vocab_dict(dict): The value will be setted to the tensor.
|
||||
|
||||
@@ -392,7 +392,7 @@ class BloomModelInferenceModel(BloomPreTrainedModel):
|
||||
elif k.endswith("mlp.dense_4h_to_h.bias"):
|
||||
self.transformer_block.ffn2_biases[idx].set_value(paddle.to_tensor(v))
|
||||
else:
|
||||
raise ValueError("Unknow weight {}".format(k))
|
||||
raise ValueError("Unknown weight {}".format(k))
|
||||
|
||||
|
||||
class BloomLMHead(nn.Layer):
|
||||
|
||||
@@ -481,7 +481,7 @@ class ChatGLMStackDyBatch(nn.Layer):
|
||||
elif k.endswith("mlp.dense_4h_to_h.bias"):
|
||||
self.transformer_block.ffn2_biases[idx].set_value(v.astype(dtype))
|
||||
else:
|
||||
print("Unknow weight {}".format(k))
|
||||
print("Unknown weight {}".format(k))
|
||||
|
||||
|
||||
@register_base_model
|
||||
|
||||
@@ -145,7 +145,7 @@ class DeepseekScalingRotaryEmbedding(nn.Layer):
|
||||
|
||||
class DeepseekScalingRotaryEmbeddingXPU(nn.Layer):
|
||||
"""
|
||||
RotaryEmbedding XPU Implemention. In XPU, cos and sin must be computed in cpu.
|
||||
RotaryEmbedding XPU Implementation. In XPU, cos and sin must be computed in cpu.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
|
||||
@@ -102,7 +102,7 @@ class GenerationInferenceModel(GenerationMixin):
|
||||
config.get("logits_processors", None),
|
||||
precache_input_spec,
|
||||
]
|
||||
# use "==" to distingusih between chatglm and chatglm_v2.
|
||||
# use "==" to distinguish between chatglm and chatglm_v2.
|
||||
if self.config["model_type"] and "chatglm" == self.config.model_type.lower():
|
||||
input_spec[2] = paddle.static.InputSpec(
|
||||
shape=[None, None, None], dtype="int64", name="position_ids"
|
||||
|
||||
@@ -432,7 +432,7 @@ class GPTInferenceModel(GPTPretrainedModel):
|
||||
elif k.endswith("linear2.bias"):
|
||||
self.transformer_block.ffn2_biases[idx].set_value(v.astype(dtype))
|
||||
else:
|
||||
raise ValueError("Unknow weight {}".format(k))
|
||||
raise ValueError("Unknown weight {}".format(k))
|
||||
|
||||
|
||||
class GPTForCausalLMInferenceModel(GenerationInferenceModel, GPTPretrainedModel):
|
||||
|
||||
@@ -121,7 +121,7 @@ class GenerationConfig:
|
||||
use_fast: (bool, optional): Whether to use fast entry of model
|
||||
for FastGeneration. Default to False.
|
||||
use_fp16_decoding: (bool, optional): Whether to use fp16 for decoding.
|
||||
Only works when fast entry is avalible. Default to False.
|
||||
Only works when fast entry is available. Default to False.
|
||||
trunc_input: (bool, optional): Whether to truncate the inputs from
|
||||
output sequences . Default to True.
|
||||
model_kwargs (dict): It can be used to specify additional kwargs
|
||||
|
||||
@@ -149,7 +149,7 @@ class TextStreamer(BaseStreamer):
|
||||
class TextIteratorStreamer(TextStreamer):
|
||||
"""
|
||||
Streamer that stores print-ready text in a queue, to be used by a downstream application as an iterator. This is
|
||||
useful for applications that benefit from acessing the generated text in a non-blocking way (e.g. in an interactive
|
||||
useful for applications that benefit from accessing the generated text in a non-blocking way (e.g. in an interactive
|
||||
Gradio demo).
|
||||
|
||||
Parameters:
|
||||
|
||||
@@ -1223,7 +1223,7 @@ class GenerationMixin(object):
|
||||
next_tokens = paddle.multinomial(probs)
|
||||
|
||||
if self.config.tensor_parallel_degree > 1:
|
||||
# Maybe no need to broadcast if seed is set correclty.
|
||||
# Maybe no need to broadcast if seed is set correctly.
|
||||
from paddle.distributed import fleet
|
||||
|
||||
try:
|
||||
|
||||
@@ -127,7 +127,7 @@ def compute_predictions(
|
||||
|
||||
nbest.append(_NbestPrediction(text=final_text, start_logit=pred.start_logit, end_logit=pred.end_logit))
|
||||
|
||||
# if we didn't inlude the empty option in the n-best, inlcude it
|
||||
# if we didn't include the empty option in the n-best, include it
|
||||
|
||||
# In very rare edge cases we could have no valid predictions. So we
|
||||
# just create a nonce prediction in this case to avoid failure.
|
||||
|
||||
@@ -188,7 +188,7 @@ class AdamWDL(AdamW):
|
||||
ratio = self.set_param_lr_fun(param_and_grad[0])
|
||||
param_and_grad[0].optimize_attr["learning_rate"] *= ratio
|
||||
|
||||
# excute Adam op
|
||||
# execute Adam op
|
||||
res = super(AdamWDL, self)._append_optimize_op(block, param_and_grad)
|
||||
param_and_grad[0].optimize_attr["learning_rate"] = prev_lr
|
||||
return res
|
||||
|
||||
@@ -934,7 +934,7 @@ def get_default_config(
|
||||
"num_stages": 4,
|
||||
}
|
||||
else:
|
||||
# Block-wise quant: BLOCK_SIZE_K must be divisable by block_shape[1]
|
||||
# Block-wise quant: BLOCK_SIZE_K must be divisible by block_shape[1]
|
||||
config = {
|
||||
"BLOCK_SIZE_M": 64,
|
||||
"BLOCK_SIZE_N": block_shape[0],
|
||||
|
||||
@@ -98,7 +98,7 @@ def extract_triton_kernel(kernel, file_name):
|
||||
elif type(kernel) == triton.runtime.autotuner.Autotuner:
|
||||
fn = kernel.fn.fn
|
||||
else:
|
||||
AssertionError("error occures")
|
||||
AssertionError("error occurs")
|
||||
py_script = textwrap.dedent(inspect.getsource(fn))
|
||||
|
||||
# @triton.jit must only appear once
|
||||
|
||||
@@ -196,7 +196,7 @@ def factorization(dimension: int, factor: int = -1) -> Tuple[int, int]:
|
||||
In LoRA with Kroneckor Product, first value is a value for weight scale.
|
||||
second value is a value for weight.
|
||||
|
||||
Becuase of non-commutative property, A⊗B ≠ B⊗A. Meaning of two matrices is slightly different.
|
||||
Because of non-commutative property, A⊗B ≠ B⊗A. Meaning of two matrices is slightly different.
|
||||
|
||||
examples)
|
||||
factor
|
||||
|
||||
@@ -318,7 +318,7 @@ class LoRAAutoModel(nn.Layer):
|
||||
if self.is_pipelinemodel and merge_tensor_parallel and self.lora_config.tensor_parallel_degree > 1:
|
||||
merge_tensor_parallel = False
|
||||
logger.warning(
|
||||
"Pipeline parallism does not support merge_tensor_parallel. Set merge_tensor_parallel to False."
|
||||
"Pipeline parallelism does not support merge_tensor_parallel. Set merge_tensor_parallel to False."
|
||||
)
|
||||
|
||||
variant = kwargs.get("variant", None)
|
||||
@@ -580,7 +580,7 @@ class LoRAAutoModel(nn.Layer):
|
||||
for k, v in config["mp_config"]["parallelize_plan"].items():
|
||||
assert (
|
||||
k not in final_config["mp_config"]["parallelize_plan"].keys()
|
||||
), f"sublayer mp_config shuld be a subset of model but got sublayer config {config['mp_config']} and model config {final_config['mp_config']}."
|
||||
), f"sublayer mp_config should be a subset of model but got sublayer config {config['mp_config']} and model config {final_config['mp_config']}."
|
||||
final_config["mp_config"]["parallelize_plan"][k] = v
|
||||
if "sp_config" in config and config["sp_config"] is not None:
|
||||
if final_config["sp_config"] is None:
|
||||
@@ -589,7 +589,7 @@ class LoRAAutoModel(nn.Layer):
|
||||
for k, v in config["sp_config"]["parallelize_plan"].items():
|
||||
assert (
|
||||
k not in final_config["sp_config"]["parallelize_plan"].keys()
|
||||
), f"sublayer sp_config shuld be a subset of model but got sublayer config {config['sp_config']} and model config {final_config['sp_config']}."
|
||||
), f"sublayer sp_config should be a subset of model but got sublayer config {config['sp_config']} and model config {final_config['sp_config']}."
|
||||
final_config["sp_config"]["parallelize_plan"][k] = v
|
||||
if "pp_config" in config and config["pp_config"] is not None:
|
||||
|
||||
|
||||
@@ -420,7 +420,7 @@ class LoRAModel(nn.Layer):
|
||||
if self.is_pipelinemodel and merge_tensor_parallel and self.lora_config.tensor_parallel_degree > 1:
|
||||
merge_tensor_parallel = False
|
||||
logger.warning(
|
||||
"Pipeline parallism does not support merge_tensor_parallel. Set merge_tensor_parallel to False."
|
||||
"Pipeline parallelism does not support merge_tensor_parallel. Set merge_tensor_parallel to False."
|
||||
)
|
||||
|
||||
variant = kwargs.get("variant", None)
|
||||
|
||||
@@ -111,7 +111,7 @@ class VeRAModel(nn.Layer):
|
||||
if self.is_pipelinemodel and merge_tensor_parallel and self.vera_config.tensor_parallel_degree > 1:
|
||||
merge_tensor_parallel = False
|
||||
logger.warning(
|
||||
"Pipeline parallism does not support merge_tensor_parallel. Set merge_tensor_parallel to False."
|
||||
"Pipeline parallelism does not support merge_tensor_parallel. Set merge_tensor_parallel to False."
|
||||
)
|
||||
|
||||
variant = kwargs.get("variant", None)
|
||||
|
||||
@@ -503,7 +503,7 @@ class SoftTemplate(Template):
|
||||
continuous token id sequence for each part in template.
|
||||
|
||||
Returns:
|
||||
`List[Dict[str, str]]`: Template with continuous prompt formated as {"soft": "xxx"}.
|
||||
`List[Dict[str, str]]`: Template with continuous prompt formatted as {"soft": "xxx"}.
|
||||
`Tuple[Dict[int, int], List[List[int]], int]`:
|
||||
- Mapping from continuous ids to word ids for initialization.
|
||||
- Continuous ids for each part. Id 0 denotes none-continuous part.
|
||||
|
||||
@@ -1208,7 +1208,7 @@ class PPOTrainer(Trainer):
|
||||
if dp_degree * sharding_degree == 1:
|
||||
return micro_batches
|
||||
|
||||
# otherwise, need to balance batch accross DP and Sharding groups
|
||||
# otherwise, need to balance batch across DP and Sharding groups
|
||||
try:
|
||||
hcg = fleet.get_hybrid_communicate_group()
|
||||
sharding_parallel_group = hcg.get_sharding_parallel_group()
|
||||
|
||||
@@ -625,12 +625,12 @@ class RLTrainer(Trainer):
|
||||
eval_tp_rank = max(tensor_parallel_rank, 0)
|
||||
group_nums = self.args.logical_process_index // old_dp_workers * eval_tp_size + eval_tp_rank
|
||||
self._data_trans_group = create_data_trans_group(global_rank, group_nums)
|
||||
# just for compatiable with old code
|
||||
# just for compatible with old code
|
||||
self._policy_model_eval_group = self._data_trans_group
|
||||
|
||||
def get_model(self, train=False):
|
||||
"""
|
||||
model visitor wrapps PipelineParalle and Inference model to do evaulation
|
||||
model visitor wraps PipelineParallel and Inference model to do evaluation
|
||||
and generation.
|
||||
"""
|
||||
if train:
|
||||
@@ -785,10 +785,10 @@ class RLTrainer(Trainer):
|
||||
NOTE: This is transparent to users.
|
||||
When using a mixed loss we often want to get the separated loss metrics,
|
||||
thus we mark loss type of each training step to separate them. This is
|
||||
not necessary since the loss would be returnd after each training step.
|
||||
However when using PipelienParallel, the loss returned is 0 when not reach
|
||||
not necessary since the loss would be returned after each training step.
|
||||
However when using PipelineParallel, the loss returned is 0 when not reach
|
||||
accumulated step and the loss returned at accumulated step is a mixed loss.
|
||||
To separate loss metrics in PipelienParallel:
|
||||
To separate loss metrics in PipelineParallel:
|
||||
1. We hack PipelineParallel._forward_step to record actual loss for each
|
||||
step in a list (only in training and not in evaluation currently).
|
||||
2. We mark the loss type only once for each step using `loss_step_indice`
|
||||
@@ -805,7 +805,7 @@ class RLTrainer(Trainer):
|
||||
"""
|
||||
Return a dict mapping loss name to value of current training step. This
|
||||
is mainly to get loss for metric logging, and it would not affect the
|
||||
training. This is mostly helpful to PipelienParallel with a mixed loss
|
||||
training. This is mostly helpful to PipelineParallel with a mixed loss
|
||||
in which the loss returned is 0 when not reach accumulated step and the
|
||||
loss returned at accumulated step is a mixed loss.
|
||||
NOTE: 1. Only when reaching accumulated step the losses returned are
|
||||
@@ -830,7 +830,7 @@ class RLTrainer(Trainer):
|
||||
mix_loss = paddle.stack(model._step_losses)
|
||||
model._step_losses = None
|
||||
else:
|
||||
# The tessor shape is not actor_model.accumulate_steps
|
||||
# The tensor shape is not actor_model.accumulate_steps
|
||||
# (args.accu_steps) but actor_trainer.args.accu_steps,
|
||||
# since actor_model is created with global pp_config
|
||||
# using global args.accu_steps which is only half of
|
||||
|
||||
@@ -139,7 +139,7 @@ def karmarkar_karp(seqlen_list: List[int], k_partitions: int, equal_size: bool):
|
||||
|
||||
def get_seqlen_balanced_partitions(seqlen_list: List[int], k_partitions: int, equal_size: bool):
|
||||
"""get order of seq lengths to make partitions balanced, this is
|
||||
used in balacing sum of seqlength across dp ranks and microbatches
|
||||
used in balancing sum of seqlength across dp ranks and microbatches
|
||||
Parameters:
|
||||
seqlen_list (List[int]):
|
||||
seq lengths of each items
|
||||
|
||||
@@ -353,7 +353,7 @@ class AlbertTokenizer(PretrainedTokenizer):
|
||||
Args:
|
||||
ids (list): A list of ids to be converted.
|
||||
skip_special_tokens (bool, optional):
|
||||
Whether or not to skip specical tokens. Defaults to `False`.
|
||||
Whether or not to skip special tokens. Defaults to `False`.
|
||||
|
||||
Returns:
|
||||
list: A list of converted tokens.
|
||||
|
||||
@@ -1236,7 +1236,7 @@ def get_configuration_file(configuration_files: List[str]) -> str:
|
||||
configuration_file = CONFIG_NAME
|
||||
|
||||
# FIXME: (wj-Mcat) remove the hard dependency of `packaging` which can compare
|
||||
# the version of package, also be uesed in `transfromer`.
|
||||
# the version of package, also be used in `transformer`.
|
||||
# **But**, we don't support version compare function now. so remove the hard dependency.
|
||||
from packaging import version
|
||||
|
||||
|
||||
@@ -439,7 +439,7 @@ def normal_fuse_split_tp(weight, tensor_parallel_degree, tensor_parallel_rank=No
|
||||
|
||||
|
||||
"""
|
||||
There're three types of MultiHeadAttention QKV Layout in Transfomers
|
||||
There're three types of MultiHeadAttention QKV Layout in Transformers
|
||||
|
||||
tensor_parallel_qkv = [q1, k1, v1, q2, k2, v2]
|
||||
naive_merged_qkv = [q1, q1, k1, k2, v1, v2]
|
||||
@@ -692,7 +692,7 @@ class StateDictNameMapping:
|
||||
return self.action == "transpose"
|
||||
|
||||
def should_merge_last_two_dim(self) -> bool:
|
||||
"""check that wether merge last two dim"""
|
||||
"""check that whether merge last two dim"""
|
||||
return self.action == "merge_last_two_dim"
|
||||
|
||||
def run(self, state_dict: dict[str, ndarray], name: str) -> ndarray:
|
||||
@@ -764,7 +764,7 @@ class TensorInfoSaver:
|
||||
"""output the summary info into different terminal
|
||||
|
||||
Args:
|
||||
output_path (Optional[str], optional): the dir/file of sumamry file. Defaults to None.
|
||||
output_path (Optional[str], optional): the dir/file of summary file. Defaults to None.
|
||||
"""
|
||||
if output_path and os.path.isdir(output_path):
|
||||
output_path = os.path.join(output_path, "tensor_summary.xlsx")
|
||||
@@ -800,10 +800,10 @@ class TensorInfoSaver:
|
||||
|
||||
|
||||
class LogitHooker:
|
||||
"""hooks for pytorch model and paddle model, used to generate the logits of elment layers"""
|
||||
"""hooks for pytorch model and paddle model, used to generate the logits of element layers"""
|
||||
|
||||
def __init__(self, mappings: List[StateDictNameMapping], tensor_info_saver: Optional[TensorInfoSaver] = None):
|
||||
"""registe the logit hooks to compare the inputs * outputs model
|
||||
"""register the logit hooks to compare the inputs * outputs model
|
||||
|
||||
Args:
|
||||
mappings (List[StateDictNameMapping]): the mappings between paddle & pytorch model
|
||||
@@ -1006,7 +1006,7 @@ class LogitComparer:
|
||||
pytorch_model: Union[Module, Dict[str, ndarray]],
|
||||
name_mappings: List[StateDictNameMapping],
|
||||
):
|
||||
"""compare the pytorch and paddle mdoel state with name mappings
|
||||
"""compare the pytorch and paddle model state with name mappings
|
||||
|
||||
Args:
|
||||
paddle_model (Union[Layer, Dict[str, ndarray]]): paddle model instance
|
||||
@@ -1045,7 +1045,7 @@ class LogitComparer:
|
||||
"""compare the logit of pytorch & paddle model
|
||||
|
||||
Returns:
|
||||
bool: if the logits is absolutly same
|
||||
bool: if the logits is absolutely same
|
||||
"""
|
||||
PaddleModel, PytorchModel = self.get_paddle_pytorch_model_classes()
|
||||
paddle_model = PaddleModel.from_pretrained(self.input_dir)
|
||||
@@ -1120,7 +1120,7 @@ class LogitComparer:
|
||||
if is_torch_available() and is_transformers_available():
|
||||
result = self.compare_logits()
|
||||
if result is True:
|
||||
logger.info("the logits between pytorch model and paddle model is absolutly same")
|
||||
logger.info("the logits between pytorch model and paddle model is absolutely same")
|
||||
else:
|
||||
logger.error(
|
||||
"the logits between pytorch model and paddle model is not same, please check it out more carefully."
|
||||
@@ -1237,7 +1237,7 @@ class ConversionMixin:
|
||||
if state_dict is None:
|
||||
with device_guard("cpu"):
|
||||
state_dict = paddle.load(weight_file, return_numpy=False)
|
||||
logger.info("Starting to convert orignal state_dict to tensor parallel state_dict.")
|
||||
logger.info("Starting to convert original state_dict to tensor parallel state_dict.")
|
||||
|
||||
state_keys_map = cls._resolve_prefix_keys(name_action_mappings.keys(), state_dict.keys(), ignore_error)
|
||||
|
||||
|
||||
@@ -274,7 +274,7 @@ def bytes_to_unicode():
|
||||
The reversible bpe codes work on unicode strings.
|
||||
This means you need a large # of unicode characters in your vocab if you want to avoid UNKs.
|
||||
When you're at something like a 10B token dataset you end up needing around 5K for decent coverage.
|
||||
This is a signficant percentage of your normal, say, 32K bpe vocab.
|
||||
This is a significant percentage of your normal, say, 32K bpe vocab.
|
||||
To avoid that, we want lookup tables between utf-8 bytes and unicode strings.
|
||||
And avoids mapping to whitespace/control characters the bpe code barfs on.
|
||||
"""
|
||||
|
||||
@@ -922,7 +922,7 @@ class DalleBartForConditionalGeneration(DalleBartPretrainedModel):
|
||||
use_fast: (bool, optional): Whether to use fast entry of model
|
||||
for FastGeneration. Default to False.
|
||||
use_fp16_decoding: (bool, optional): Whether to use fp16 for decoding.
|
||||
Only works when fast entry is avalible. Default to False.
|
||||
Only works when fast entry is available. Default to False.
|
||||
condition_scale (float, optional): The scale of super conditioning. See
|
||||
`this twitter <https://twitter.com/RiversHaveWings/status/1478093658716966912>`__
|
||||
Default to 1.0.
|
||||
|
||||
@@ -452,7 +452,7 @@ def center_to_corners_format(bboxes_center: TensorType) -> TensorType:
|
||||
|
||||
center format: contains the coordinate for the center of the box and its width, height dimensions
|
||||
(center_x, center_y, width, height)
|
||||
corners format: contains the coodinates for the top-left and bottom-right corners of the box
|
||||
corners format: contains the coordinates for the top-left and bottom-right corners of the box
|
||||
(top_left_x, top_left_y, bottom_right_x, bottom_right_y)
|
||||
"""
|
||||
# Function is used during model forward pass, so we use the input framework if possible, without
|
||||
@@ -494,7 +494,7 @@ def corners_to_center_format(bboxes_corners: TensorType) -> TensorType:
|
||||
"""
|
||||
Converts bounding boxes from corners format to center format.
|
||||
|
||||
corners format: contains the coodinates for the top-left and bottom-right corners of the box
|
||||
corners format: contains the coordinates for the top-left and bottom-right corners of the box
|
||||
(top_left_x, top_left_y, bottom_right_x, bottom_right_y)
|
||||
center format: contains the coordinate for the center of the box and its the width, height dimensions
|
||||
(center_x, center_y, width, height)
|
||||
|
||||
@@ -33,7 +33,7 @@ def bytes_to_unicode():
|
||||
The reversible bpe codes work on unicode strings.
|
||||
This means you need a large # of unicode characters in your vocab if you want to avoid UNKs.
|
||||
When you're at something like a 10B token dataset you end up needing around 5K for decent coverage.
|
||||
This is a signficant percentage of your normal, say, 32K bpe vocab.
|
||||
This is a significant percentage of your normal, say, 32K bpe vocab.
|
||||
To avoid that, we want lookup tables between utf-8 bytes and unicode strings.
|
||||
And avoids mapping to whitespace/control characters the bpe code barfs on.
|
||||
"""
|
||||
|
||||
@@ -278,11 +278,11 @@ def _transformer_encoder_fwd(
|
||||
# MultiHeadAttention not so efficiently, and maybe optimize it later.
|
||||
if cache is None and getattr(self, "_use_cache", False):
|
||||
cache = [tuple(self.layers[0].gen_cache(src))] * len(self.layers)
|
||||
# To be compatible with `TransformerEncoder.forward`, `_use_cache` defualts
|
||||
# To be compatible with `TransformerEncoder.forward`, `_use_cache` defaults
|
||||
# to True when cache is not None.
|
||||
new_caches = [] if cache is not None and getattr(self, "_use_cache", True) else None
|
||||
all_attentions = [] if output_attentions else None
|
||||
# NOTE: Also includes embeding output which is same as HF.
|
||||
# NOTE: Also includes embedding output which is same as HF.
|
||||
all_hidden_states = [output] if output_hidden_states else None
|
||||
for i, mod in enumerate(self.layers):
|
||||
# if output has no gradient, recompute is unnecessary
|
||||
|
||||
@@ -591,19 +591,19 @@ def _partion_for_pipeline_mode(keys):
|
||||
keys = list(keys)
|
||||
start_idx = -1
|
||||
prefix_str = None
|
||||
parttion_map = {}
|
||||
partition_map = {}
|
||||
for k in keys:
|
||||
prefix = layer_prefix(k)
|
||||
if prefix != prefix_str:
|
||||
prefix_str = prefix
|
||||
start_idx += 1
|
||||
parttion_map[k] = start_idx
|
||||
partition_map[k] = start_idx
|
||||
|
||||
# if only one parttion, we don't parttion it
|
||||
# if only one partition, we don't partition it
|
||||
if start_idx < 1:
|
||||
return {keys[i]: i for i in range(len(keys))}
|
||||
|
||||
return parttion_map
|
||||
return partition_map
|
||||
|
||||
|
||||
def shard_checkpoint(
|
||||
@@ -808,7 +808,7 @@ def load_sharded_checkpoint(model, folder, variant=None, strict=True, prefer_saf
|
||||
|
||||
|
||||
def faster_set_state_dict(model, state_dict, strict_dtype=True):
|
||||
# the state_dict will be destroied.
|
||||
# the state_dict will be destroyed.
|
||||
unused_keys = set(state_dict.keys())
|
||||
unset_keys = set(model.state_dict().keys())
|
||||
with paddle.no_grad():
|
||||
@@ -891,7 +891,7 @@ def _convert_state_dict_dtype_and_shape(state_dict, model_to_load):
|
||||
if key in list(state_dict.keys()):
|
||||
if isinstance(state_dict[key], np.ndarray):
|
||||
raise ValueError(
|
||||
"convert_state_dict_dtype expected paddle.Tensor not numpy.ndarray, plase convert numpy.ndarray to paddle.Tensor"
|
||||
"convert_state_dict_dtype expected paddle.Tensor not numpy.ndarray, please convert numpy.ndarray to paddle.Tensor"
|
||||
)
|
||||
# confirm parameter cast is executed on the same device as model
|
||||
# TODO: cast(FP32 -> FP16) has diff on different devices, need to fix it
|
||||
@@ -1879,7 +1879,7 @@ class PretrainedModel(Layer, GenerationMixin, ConversionMixin):
|
||||
elif "pytorch_model.bin" in str(resolved_archive_file):
|
||||
if not from_hf_hub and not convert_from_torch:
|
||||
raise ValueError(
|
||||
f"Download pytorch wight in "
|
||||
f"Download pytorch weight in "
|
||||
f" {resolved_archive_file}. Please set convert_from_torch=True in from_pretrained. eg, Model.from_pretrained(model_name, convert_from_torch=True) "
|
||||
)
|
||||
|
||||
@@ -2832,7 +2832,7 @@ class PretrainedModel(Layer, GenerationMixin, ConversionMixin):
|
||||
for k, v in config["mp_config"]["parallelize_plan"].items():
|
||||
assert (
|
||||
k not in final_config["mp_config"]["parallelize_plan"].keys()
|
||||
), f"sublayer mp_config shuld be a subset of model but got sublayer config {config['mp_config']} and model config {final_config['mp_config']}."
|
||||
), f"sublayer mp_config should be a subset of model but got sublayer config {config['mp_config']} and model config {final_config['mp_config']}."
|
||||
final_config["mp_config"]["parallelize_plan"][k] = v
|
||||
if "sp_config" in config and config["sp_config"] is not None:
|
||||
if final_config["sp_config"] is None:
|
||||
@@ -2841,7 +2841,7 @@ class PretrainedModel(Layer, GenerationMixin, ConversionMixin):
|
||||
for k, v in config["sp_config"]["parallelize_plan"].items():
|
||||
assert (
|
||||
k not in final_config["sp_config"]["parallelize_plan"].keys()
|
||||
), f"sublayer sp_config shuld be a subset of model but got sublayer config {config['sp_config']} and model config {final_config['sp_config']}."
|
||||
), f"sublayer sp_config should be a subset of model but got sublayer config {config['sp_config']} and model config {final_config['sp_config']}."
|
||||
final_config["sp_config"]["parallelize_plan"][k] = v
|
||||
if "pp_config" in config and config["pp_config"] is not None:
|
||||
if isinstance(config["pp_config"]["split_spec"], str):
|
||||
|
||||
@@ -173,7 +173,7 @@ class CosineDecayWithWarmup(LambdaDecay):
|
||||
Creates a learning rate scheduler, which increases learning rate linearly
|
||||
from 0 to given `learning_rate`, after this warmup period learning rate
|
||||
would be decreased following the values of the cosine function. If
|
||||
`with_hard_restarts` is True, the cosine function could have serveral hard
|
||||
`with_hard_restarts` is True, the cosine function could have several hard
|
||||
restarts.
|
||||
|
||||
Args:
|
||||
|
||||
@@ -200,7 +200,7 @@ def is_chinese_char(cp):
|
||||
|
||||
|
||||
def _is_nonnormalized_char(char):
|
||||
"""Check whther `chars` is a non-normalized character."""
|
||||
"""Check whether `chars` is a non-normalized character."""
|
||||
cp = ord(char)
|
||||
if (
|
||||
(0xFF00 <= cp <= 0xFFEF)
|
||||
@@ -807,7 +807,7 @@ class ChatTemplateMixin:
|
||||
|
||||
def _extract_non_learnable_parts(self, origin_msg: List[Dict[str, str]], split_s: List[str]):
|
||||
"""Split the entire chat by specified words. Extract the non-learnable parts."""
|
||||
# distingish and replace the special words in original string to an uncompiled form: Like | -> \|
|
||||
# distinguish and replace the special words in original string to an uncompiled form: Like | -> \|
|
||||
regex_pattern = "|".join(map(re.escape, split_s))
|
||||
# splited by replaced specified words
|
||||
non_learnable_parts = re.split(
|
||||
@@ -1585,7 +1585,7 @@ class PretrainedTokenizer(ChatTemplateMixin, PretrainedTokenizerBase):
|
||||
sequence = ids + pair_ids if pair else ids
|
||||
token_type_ids = [0] * len(ids) + ([0] * len(pair_ids) if pair else [])
|
||||
encoded_inputs["offset_mapping"] = offset_mapping
|
||||
# Build output dictionnary
|
||||
# Build output dictionary
|
||||
encoded_inputs["input_ids"] = sequence
|
||||
if return_token_type_ids:
|
||||
encoded_inputs["token_type_ids"] = token_type_ids
|
||||
|
||||
@@ -1561,7 +1561,7 @@ class PretrainedTokenizerBase(SpecialTokensMixin):
|
||||
# From HF Hub or AI Studio
|
||||
if from_hf_hub or from_aistudio:
|
||||
# Only include the necessary resource files specified by the tokenizer cls
|
||||
# Deep copy to avoid modifiying the class attributes
|
||||
# Deep copy to avoid modifying the class attributes
|
||||
vocab_files = copy.deepcopy(cls.resource_files_names)
|
||||
vocab_files["tokenizer_config_file"] = cls.tokenizer_config_file
|
||||
|
||||
@@ -3119,7 +3119,7 @@ class PretrainedTokenizerBase(SpecialTokensMixin):
|
||||
sequence = ids + pair_ids if pair else ids
|
||||
token_type_ids = [0] * len(ids) + ([0] * len(pair_ids) if pair else [])
|
||||
|
||||
# Build output dictionnary
|
||||
# Build output dictionary
|
||||
encoded_inputs["input_ids"] = sequence
|
||||
if return_token_type_ids:
|
||||
encoded_inputs["token_type_ids"] = token_type_ids
|
||||
|
||||
@@ -205,10 +205,10 @@ def adapt_stale_fwd_patch(self, name, value):
|
||||
if self.__module__.startswith("paddlenlp"):
|
||||
warnings.warn(
|
||||
f"The `forward` method of {self.__class__ if isinstance(self, Layer) else self} is patched and the patch "
|
||||
"might be based on an old oversion which missing some "
|
||||
"might be based on an old version which missing some "
|
||||
f"arguments compared with the latest, such as {new_args}. "
|
||||
"We automatically add compatibility on the patch for "
|
||||
"these arguemnts, and maybe the patch should be updated."
|
||||
"these arguments, and maybe the patch should be updated."
|
||||
)
|
||||
else:
|
||||
warnings.warn(
|
||||
@@ -216,7 +216,7 @@ def adapt_stale_fwd_patch(self, name, value):
|
||||
"is patched and the patch might be conflict with patches made "
|
||||
f"by paddlenlp which seems have more arguments such as {new_args}. "
|
||||
"We automatically add compatibility on the patch for "
|
||||
"these arguemnts, and maybe the patch should be updated."
|
||||
"these arguments, and maybe the patch should be updated."
|
||||
)
|
||||
if isinstance(self, Layer) and inspect.isfunction(value):
|
||||
|
||||
@@ -450,7 +450,7 @@ def paddlenlp_hub_download(
|
||||
|
||||
# Download from custom model url
|
||||
if is_url(repo_id):
|
||||
# check wether the target file exist in the comunity bos server
|
||||
# check wether the target file exist in the community bos server
|
||||
if url_file_exists(repo_id):
|
||||
logger.info(f"Downloading {repo_id}")
|
||||
weight_file_path = get_path_from_url_with_filelock(repo_id, cache_dir)
|
||||
@@ -483,7 +483,7 @@ def paddlenlp_hub_download(
|
||||
community_model_file_path = "/".join(url_list)
|
||||
assert is_url(community_model_file_path)
|
||||
|
||||
# check wether the target file exist in the comunity bos server
|
||||
# check wether the target file exist in the community bos server
|
||||
if url_file_exists(community_model_file_path):
|
||||
logger.info(f"Downloading {community_model_file_path}")
|
||||
weight_file_path = get_path_from_url_with_filelock(community_model_file_path, cache_dir)
|
||||
|
||||
Reference in New Issue
Block a user