TimesFM(Time Series Foundation Model)安装(2)

TimesFM(Time Series Foundation Model)安装简介

readme

TimesFM(Time Series Foundation Model)安装简介(1)-CSDN博客icon-default.png?t=O83Ahttps://blog.csdn.net/chenchihwen/article/details/144359861?spm=1001.2014.3001.5501

在Window 上安装并执行出现报错,

{"name": "TypeError","message": "TimesFmBase.__init__() got an unexpected keyword argument 'context_len'","stack": "---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[9], line 83 from jax._src import config4 config.update(5     \"jax_platforms\", {\"cpu\": \"cpu\", \"gpu\": \"cuda\", \"tpu\": \"\"}[timesfm_backend]6 )
----> 8 model = timesfm.TimesFm(9     context_len=512,10     horizon_len=128,11     input_patch_len=32,12     output_patch_len=128,13     num_layers=20,14     model_dims=1280,15     backend=timesfm_backend,16 )17 model.load_from_checkpoint(repo_id=\"google/timesfm-1.0-200m\")TypeError: TimesFmBase.__init__() got an unexpected keyword argument 'context_len'"
}

决定在 小红帽ubuntu UBUNTU

安装 timesFM

在 ide.cloud.tencent.com 的环境上进行安装 环境 

We recommend at least 16GB RAM to load TimesFM dependencies.

慎选环境,确保>16G

安装Conda  3.10 python

重要步骤 安装  pyenv and poetry

## Installation

### Local installation using poetry

We will be using `pyenv` and `poetry`. In order to set these things up please follow the instructions [here](https://substack.com/home/post/p-148747960?r=28a5lx&utm_campaign=post&utm_medium=web). Note that the PAX (or JAX) version needs to run on python 3.10.x and the PyTorch version can run on >=3.11.x. Therefore make sure you have two versions of python installed:

确认已经完成安装

(base) root@VM-0-170-ubuntu:/workspace/timesfm# pyenv --version
pyenv 2.4.22
(base) root@VM-0-170-ubuntu:/workspace/timesfm# poetry --version
Poetry (version 1.8.5)

这里安装完需要设置环境变量,如果不能看到 version 版本时

Add `export PATH="/root/.local/bin:$PATH"` to your shell configuration file

要修改环境变量

nano ~/.bash_profile

nano ~/.bash_profile 执行后添加环境变量,在 bash_profile里应该是这个参数

/root/.bash_profile                                                                                              
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
export PATH="/root/.local/bin:$PATH"

修改后要执行 ctrl-O  : write out

再执行 ctrl-X :Exit

刷新环境变量,这时后才会生效,执行以下代码

source ~/.bash_profile

克隆timesFM

git clone https://github.com/google-research/timesfm/gitgit clone https://github.com/google-research/timesfm.git
Cloning into 'timesfm'...
remote: Enumerating objects: 667, done.
remote: Counting objects: 100% (665/665), done.
remote: Compressing objects: 100% (316/316), done.
remote: Total 667 (delta 353), reused 568 (delta 306), pack-reused 2 (from 1)
Receiving objects: 100% (667/667), 1.94 MiB | 3.76 MiB/s, done.
Resolving deltas: 100% (353/353), done.

在 timesfm 下找到 pyproject.toml 在最后面添加 aliyun 的source,不然安装不起来

[[tool.poetry.source]]
name = "aliyun"
url = "https://mirrors.aliyun.com/pypi/simple/"
priority = "primary"

 Note that the PAX (or JAX) version needs to run on python 3.10.x and the PyTorch version can run on >=3.11.x. Therefore make sure you have two versions of python installed:

pyenv install 3.10
pyenv install 3.11
pyenv versions # to list the versions available (lets assume the versions are 3.10.15 and 3.11.10)

For PAX version installation do the following.

在 timesfm git 目录下 执行

pyenv local 3.10.15
poetry env use 3.10.15
poetry lock
poetry install -E  pax

在 timesfm git 目录下 执行

➜  timesfm git:(master) pyenv local 3.10.15
poetry env use 3.10.15
poetry lock
poetry install -E  pax
pyenv: version `3.10.15' not installedCould not find the python executable python3.10
Creating virtualenv timesfm-jW3uZHTw-py3.11 in /root/.cache/pypoetry/virtualenvs
Updating dependencies
Resolving dependencies... (378.2s)

过程中还要安装numpy

根据 readme 

Please look into the README files in the respective benchmark directories within `experiments/` for instructions for running TimesFM on the respective benchmarks.

## Running TimesFM on the benchmark

We need to add the following packages for running these benchmarks. Follow the installation instructions till before `poetry lock`. Then,

```
poetry add git+https://github.com/awslabs/gluon-ts.git
poetry lock
poetry install --only <pax or pytorch>
```

To run the timesfm on the benchmark do:

```
poetry run python3 -m experiments.extended_benchmarks.run_timesfm --model_path=google/timesfm-1.0-200m(-pytorch) --backend="gpu"
```

 执行 poetry shell 

(base) root@VM-0-170-ubuntu:/workspace/timesfm# poetry shell
Spawning shell within /root/.cache/pypoetry/virtualenvs/timesfm-p1AFFT58-py3.10
. /root/.cache/pypoetry/virtualenvs/timesfm-p1AFFT58-py3.10/bin/activate
bash: __vsc_prompt_cmd_original: command not found
(base) root@VM-0-170-ubuntu:/workspace/timesfm# . /root/.cache/pypoetry/virtualenvs/timesfm-p1AFFT58-py3.10/bin/activate
bash: __vsc_prompt_cmd_original: command not found
(timesfm-py3.10) (base) root@VM-0-170-ubuntu:/workspace/timesfm# 

执行命令 poetry run python3 -m experiments.extended_benchmarks.run_timesfm --model_path=google/timesfm-1.0-200m

在成功执行之前,还需安装 jax, 

run_timesfm.py 的代码如下

# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Evaluation script for timesfm."""import os
import sys
import timefrom absl import flags
import numpy as np
import pandas as pd
import timesfmfrom .utils import ExperimentHandlerdataset_names = ["m1_monthly","m1_quarterly","m1_yearly","m3_monthly","m3_other","m3_quarterly","m3_yearly","m4_quarterly","m4_yearly","tourism_monthly","tourism_quarterly","tourism_yearly","nn5_daily_without_missing","m5","nn5_weekly","traffic","weather","australian_electricity_demand","car_parts_without_missing","cif_2016","covid_deaths","ercot","ett_small_15min","ett_small_1h","exchange_rate","fred_md","hospital",
]context_dict = {"cif_2016": 32,"tourism_yearly": 64,"covid_deaths": 64,"tourism_quarterly": 64,"tourism_monthly": 64,"m1_monthly": 64,"m1_quarterly": 64,"m1_yearly": 64,"m3_monthly": 64,"m3_other": 64,"m3_quarterly": 64,"m3_yearly": 64,"m4_quarterly": 64,"m4_yearly": 64,
}_MODEL_PATH = flags.DEFINE_string("model_path", "google/timesfm-1.0-200m","Path to model")
_BATCH_SIZE = flags.DEFINE_integer("batch_size", 64, "Batch size")
_HORIZON = flags.DEFINE_integer("horizon", 128, "Horizon")
_BACKEND = flags.DEFINE_string("backend", "gpu", "Backend")
_NUM_JOBS = flags.DEFINE_integer("num_jobs", 1, "Number of jobs")
_SAVE_DIR = flags.DEFINE_string("save_dir", "./results", "Save directory")QUANTILES = list(np.arange(1, 10) / 10.0)def main():results_list = []tfm = timesfm.TimesFm(hparams=timesfm.TimesFmHparams(backend=_BACKEND.value,per_core_batch_size=_BATCH_SIZE.value,horizon_len=_HORIZON.value,),checkpoint=timesfm.TimesFmCheckpoint(huggingface_repo_id=_MODEL_PATH.value),)run_id = np.random.randint(100000)model_name = "timesfm"for dataset in dataset_names:print(f"Evaluating model {model_name} on dataset {dataset}", flush=True)exp = ExperimentHandler(dataset, quantiles=QUANTILES)if dataset in context_dict:context_len = context_dict[dataset]else:context_len = 512train_df = exp.train_dffreq = exp.freqinit_time = time.time()fcsts_df = tfm.forecast_on_df(inputs=train_df,freq=freq,value_name="y",model_name=model_name,forecast_context_len=context_len,num_jobs=_NUM_JOBS.value,)total_time = time.time() - init_timetime_df = pd.DataFrame({"time": [total_time], "model": model_name})results = exp.evaluate_from_predictions(models=[model_name],fcsts_df=fcsts_df,times_df=time_df)print(results, flush=True)results_list.append(results)results_full = pd.concat(results_list)save_path = os.path.join(_SAVE_DIR.value, str(run_id))print(f"Saving results to {save_path}", flush=True)os.makedirs(save_path, exist_ok=True)results_full.to_csv(f"{save_path}/results.csv")if __name__ == "__main__":FLAGS = flags.FLAGSFLAGS(sys.argv)main()

执行结果:

(timesfm-py3.10) (base) root@VM-0-170-ubuntu:/workspace/timesfm# poetry run python3 -m experiments.extended_benchmarks.run_timesfm --model_path=google/timesfm-1.0-200m
TimesFM v1.2.0. See https://github.com/google-research/timesfm/blob/master/README.md for updated APIs.
Loaded Jax TimesFM.
/root/.cache/pypoetry/virtualenvs/timesfm-p1AFFT58-py3.10/lib/python3.10/site-packages/gluonts/json.py:102: UserWarning: Using `json`-module for json-handling. Consider installing one of `orjson`, `ujson` to speed up serialization and deserialization.warnings.warn(
Fetching 5 files: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:00<00:00, 63937.56it/s]
Multiprocessing context has already been set.
Constructing model weights.
Constructed model weights in 2.83 seconds.
Restoring checkpoint from /root/.cache/huggingface/hub/models--google--timesfm-1.0-200m/snapshots/8775f7531211ac864b739fe776b0b255c277e2be/checkpoints.
WARNING:absl:No registered CheckpointArgs found for handler type: <class 'paxml.checkpoints.FlaxCheckpointHandler'>
WARNING:absl:Configured `CheckpointManager` using deprecated legacy API. Please follow the instructions at https://orbax.readthedocs.io/en/latest/api_refactor.html to migrate by May 1st, 2024.
WARNING:absl:train_state_unpadded_shape_dtype_struct is not provided. We assume `train_state` is unpadded.
ERROR:absl:For checkpoint version > 1.0, we require users to provide`train_state_unpadded_shape_dtype_struct` during checkpointsaving/restoring, to avoid potential silent bugs when loadingcheckpoints to incompatible unpadded shapes of TrainState.
Restored checkpoint in 1.50 seconds.
Jitting decoding.
Jitted decoding in 20.78 seconds.
Evaluating model timesfm on dataset m1_monthly
/root/.cache/pypoetry/virtualenvs/timesfm-p1AFFT58-py3.10/lib/python3.10/site-packages/gluonts/time_feature/seasonality.py:47: FutureWarning: 'M' is deprecated and will be removed in a future version, please use 'ME' instead.offset = pd.tseries.frequencies.to_offset(freq)
Multiprocessing context has already been set.
/root/miniforge3/lib/python3.10/multiprocessing/popen_fork.py:66: RuntimeWarning: os.fork() was called. os.fork() is incompatible with multithreaded code, and JAX is multithreaded, so this will likely lead to a deadlock.self.pid = os.fork()
Processing dataframe with single process.
Finished preprocessing dataframe.
Finished forecasting.

 预测结果

           dataset       metric    model        value
0  tourism_monthly          mae  timesfm  1970.148438
1  tourism_monthly         mase  timesfm     1.541883
2  tourism_monthly  scaled_crps  timesfm     0.121862
3  tourism_monthly        smape  timesfm     0.101539
4  tourism_monthly         time  timesfm     0.762044---------------dataset       metric    model        value
0  tourism_quarterly          mae  timesfm  7439.246094
1  tourism_quarterly         mase  timesfm     1.731996
2  tourism_quarterly  scaled_crps  timesfm     0.087743
3  tourism_quarterly        smape  timesfm     0.083795
4  tourism_quarterly         time  timesfm     0.839042-----------------dataset       metric    model         value
0  tourism_yearly          mae  timesfm  82434.085938
1  tourism_yearly         mase  timesfm      3.233205
2  tourism_yearly  scaled_crps  timesfm      0.129402
3  tourism_yearly        smape  timesfm      0.181012
4  tourism_yearly         time  timesfm      1.023866

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/889368.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Cesium进阶教程——自定义图形、外观、绘图基础、现有着色器移植至Cesium、ShadowMapping、视频GIS、模型压平、卷帘

基础必看 https://blog.csdn.net/m0_55049655/article/details/139720401 参考路线 http://www.xt3d.online/tutorial/further/article.html 自定义图形 https://blog.csdn.net/m0_55049655/article/details/138908327 https://blog.csdn.net/m0_55049655/article/details/14…

国际荐酒师(香港)协会亮相第六届地博会助力中欧地标交流合作

国际荐酒师&#xff08;香港&#xff09;协会亮相第六届知交会暨地博会&#xff0c;助力中欧地理标志产品交流合作 12月9日&#xff0c;第六届粤港澳大湾区知识产权交易博览会暨国际地理标志产品交易博览会&#xff08;以下简称“第六届知交会暨地博会”&#xff09;在中新广州…

spring boot之@Import注解的应用

我们知道spring boot会通过ComponentScan定义包扫描路径进行业务定义的bean的加载&#xff0c;但是对于很多不在此包路径下定义的bean怎么办呢&#xff1f;比如其他jar包中定义的。这时候import就发挥作用了&#xff0c;通过它也可以实现bean的定义。具体是怎么做的呢&#xff…

【Liunx篇】基础开发工具 - vim

文章目录 一.vim的基本概念1.正常/命令模式2.插入模式3.底行模式/末行模式4.视图模式5.替换模式 二.vim的基本操作1.进入vim&#xff1a;2.退出vim: 三.vim正常模式命令集1.光标定位&#xff1a;2.复制/粘贴3.撤销4.剪切/删除5. 更改 四.vim底行模式命令集1.保存/退出2.调出行号…

Windows安装WSL子系统及docker,以及WSL和docker配置、使用及问题解决

在Windows操作系统中,Ubuntu子系统(也称为Windows Subsystem for Linux, WSL)为开发者提供了一个在Windows环境下运行Linux环境的平台。然而,有时用户在按照Ubuntu子系统或者使用WSL时,可能会遇到各种问题,下面总结一下解决方式。 想要在Windows上安装Docker(实际上是基…

【Golang】Go语言编程思想(六):Channel,第三节,使用Channel实现树的遍历

使用 Channel 实现树的遍历 tree 在此处简单回顾一下之前学过的二叉树遍历&#xff0c;首先新建一个名为 tree 的目录&#xff0c;并在其下对文件和子目录进行如下组织&#xff1a; 其中 node.go 存放的是 Node 的定义&#xff1a; package treeimport "fmt"type…

IDEA 2024 版本配置热部署

在实际开发过程中&#xff0c;每次修改代码就得将项目重启&#xff0c;重新部署&#xff0c;对于一些大型应用来说&#xff0c;重启时间需要花费大量的时间成本。对于一个后端开发者来说&#xff0c;重启过程确实很难受啊 采用下面三步骤可以完成 1.在IDEA中settings中搜索Debb…

【目标跟踪】DUT Anti-UAV数据集详细介绍

DUT Anti-UAV数据集是大连理工大学的团队公开的数据集&#xff08;DUT是他们学校的简称&#xff09;&#xff0c;其中包括了两个子数据集&#xff1a;目标检测和目标跟踪&#xff08;也就是说&#xff0c;目标检测和目标跟踪都可以用这个数据集&#xff09;。该数据集为可见光模…

经典多模态模型CLIP - 直观且详尽的解释

阅读原文 在本文中&#xff0c;您将了解“contrastive language-image pre-training”&#xff08;CLIP&#xff09;&#xff0c;这是一种创建视觉和语言表示的策略&#xff0c;效果非常好&#xff0c;可用于制作高度特定且性能卓越的分类器&#xff0c;而无需任何训练数据。本…

探索云原生安全解决方案的未来

我们是否充分意识到云端所面临的网络安全威胁&#xff1f; 在当今互联互通的世界中&#xff0c;维护安全的环境至关重要。云的出现扩大了潜在威胁的范围&#xff0c;因为它催生了机器身份&#xff08;称为非人类身份 (NHI)&#xff09;及其秘密。随着组织越来越多地转向云原生…

项目组件框架介绍[etcd]

文章目录 前言etcd安装Ubuntu 上通过包管理器安装通过源码安装配置 客户端开发包开发包的安装接口介绍添加一个键值对获取一个键值对租约保活机制监听 封装服务注册与发现服务注册服务发现 前言 Etcd 是一个 golang 编写的分布式、高可用的一致性键值存储系统&#xff0c;用于配…

在Windows 10中使用SSH远程连接服务器(附花生壳操作方法)

SSH 在 linux 中是一种重要的系统组件&#xff0c;用户可以使用 SSH 来远程连接 linux 系统的计算机&#xff0c;或者传输文件。不过在 win10 以前&#xff0c;windows 并不原生支持 SSH&#xff0c;需要借助第三方工具来使用 SSH 功能。而实际上&#xff0c;微软在 2015 年就曾…

【环境搭建】Jeecg-Boot v3.5.0 Docker搭建

前言 最近需要复现JeecgBoot的SQL注入漏洞&#xff0c;必须要搭建JeecgBoot v3.5.0这个版本才行&#xff0c;DockerHub没人push这个版本的&#xff0c;相关博客也比较少&#xff0c;所以自己来搭建&#xff0c;记录一下过程。 前置环境 Ubuntu 20.04Docker version 27.3.1do…

【人工智能基础06】人工神经网络(练习题):神经网络的计算、激活函数的选择与神经网络的退化

文章目录 1. 基于神经网络计算心理健康程度2. 添加激活函数的神经网络计算3. 使用神经网络预测小胖是否会变胖4. 激活函数选择的讨论5. 神经网络的设计6. 深度线性模型的表达能力线性模型7. 神经网络退化 主要讨论的内容 什么是人工神经网络&#xff0c;相关计算反向传播算法的…

STM32 串口收发文本数据包

单片机学习&#xff01; 目录 前言 一、文本数据包格式 二、串口收发文本数据包代码 三、代码解析 3.1 标志位清除 3.2 数据包接收 四、代码问题改进 总结 前言 本文介绍了串口收发文本数据包程序设计的思路并详解代码作用。 一、文本数据包格式 文本数据包的格式的定义…

预言机调研

预言机 1. 概述 预言机主要承担两个工作&#xff0c;一是验证信息可靠性&#xff0c;二是传递信息。 如果没有预言机&#xff0c;区块链的信息来源将仅限于其内部数据&#xff0c;其广泛使用的潜力和可能性将会大大降低。 区块链预言机是区块链与外部世界之间的桥梁。它们使区…

【1211更新】腾讯混元Hunyuan3D-1文/图生3D模型云端镜像一键运行

目录 项目介绍 显存占用 11月21 新增纹理烘焙模块Dust3R 烘焙相关参数&#xff1a; AutoDL云端镜像 启动说明 标准模型下载 项目介绍 https://github.com/Tencent/Hunyuan3D-1 腾讯混元 3D 生成模型,支持文本和图像条件生成(对于文生3D&#xff0c;支持中/英双语生成)…

【前端】HTML标签汇总

目录 展示用户信息的标签 1.文本标签 span 2.标题标签 h1~h6 3.竖着布局的标签 div 4.段落标签 p 5.超链接标签 a 5.1跳转至网上的资源 5.2锚点 6.列表标签 6.1有序列表 ol 6.2无序列表 ul 7.图片标签 img 7.1相对路径 7.1.1兄弟关系 7.1.2叔侄关系 7.1.3表兄弟…

今天你学C++了吗?——C++中的类与对象(日期类的实现)——实践与知识的碰撞❤

♥♥♥~~~~~~欢迎光临知星小度博客空间~~~~~~♥♥♥ ♥♥♥零星地变得优秀~也能拼凑出星河~♥♥♥ ♥♥♥我们一起努力成为更好的自己~♥♥♥ ♥♥♥如果这一篇博客对你有帮助~别忘了点赞分享哦~♥♥♥ ♥♥♥如果有什么问题可以评论区留言或者私信我哦~♥♥♥ ✨✨✨✨✨✨ 个…

负载均衡和tomcat

一、负载均衡 1.相关概念 nginx的反向代理<-->负载均衡 负载均衡 将四层或者是七层的请求分配到多台后端的服务器上&#xff0c;从而分担整个业务的负载。提高系统的稳定性&#xff0c;也可以提供高可用&#xff08;备灾&#xff0c;其中的一台后端服务器如果发生故障…