From 904c740ccbb4da470f87c70a2606cf7fca408210 Mon Sep 17 00:00:00 2001 From: hxdtest <107838921+hxdtest@users.noreply.github.com> Date: Wed, 14 Feb 2024 04:18:45 +0800 Subject: [PATCH] Add support for Python 3.8 (#448) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 玄钛 Co-authored-by: Pete Co-authored-by: epwalsh --- CHANGELOG.md | 1 + olmo/model.py | 9 ++++++++- olmo/util.py | 6 +++++- pyproject.toml | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 657b6e1a4..59e5206a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed default value of `--tokenizer` argument to `scripts/prepare_tulu_data.py` to be an absolute path, not relative path, the script can be run from other directories. - Added the option to directly pass input embeddings to `OLMo` and `OLMoForCausalLM`. +- Added support for Python 3.8. ### Added - Added `output_hidden_states` argument and associated functionality to `OLMo` and `OLMoForCausalLM` to return model intermediate hidden states. diff --git a/olmo/model.py b/olmo/model.py index 63751c7f2..466a37a99 100644 --- a/olmo/model.py +++ b/olmo/model.py @@ -8,9 +8,9 @@ import logging import math +import sys from abc import abstractmethod from collections import defaultdict -from collections.abc import MutableMapping from functools import partial from typing import ( Callable, @@ -46,6 +46,13 @@ from .initialization import ModuleType, init_weights from .torch_util import ensure_finite_ +if sys.version_info.minor > 8: + from collections.abc import MutableMapping +elif sys.version_info.minor == 8: + from typing import MutableMapping +else: + raise SystemExit("This script supports Python 3.8 or higher") + __all__ = [ "LayerNormBase", "LayerNorm", diff --git a/olmo/util.py b/olmo/util.py index 62e964b5d..71ee67e60 100644 --- a/olmo/util.py +++ b/olmo/util.py @@ -7,7 +7,6 @@ import warnings from datetime import datetime from enum import Enum -from functools import cache from itertools import cycle, islice from pathlib import Path from queue import Queue @@ -34,6 +33,11 @@ ) from .torch_util import get_global_rank, get_local_rank, get_node_rank, is_distributed +try: + from functools import cache +except ImportError: + from functools import lru_cache as cache + class StrEnum(str, Enum): """ diff --git a/pyproject.toml b/pyproject.toml index ba451325f..db9af8201 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ description = "Open Language Model (OLMo)" authors = [ { name = "Allen Institute for Artificial Intelligence", email = "olmo@allenai.org" } ] -requires-python = ">=3.9" +requires-python = ">=3.8" license = { file = "LICENSE" } dependencies = [ "numpy",